Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Django react应用程序停靠在一起时出错_Django_Reactjs_Docker_Docker Compose - Fatal编程技术网

将Django react应用程序停靠在一起时出错

将Django react应用程序停靠在一起时出错,django,reactjs,docker,docker-compose,Django,Reactjs,Docker,Docker Compose,我已经成功对接了我的Django应用程序,但是遇到了麻烦,我对接了与Django应用程序连接的react应用程序 这是我下面的Dockerfile # Pull base image FROM python:3 # Set environment varibles ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # Set work directory, we can name it whatever we want WORKDIR

我已经成功对接了我的Django应用程序,但是遇到了麻烦,我对接了与Django应用程序连接的react应用程序

这是我下面的
Dockerfile

# Pull base image
FROM python:3

# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory, we can name it whatever we want
WORKDIR /djangobackend

# Install dependencies
# Copy requirement file from the docker workdir we defined named djangodocker
COPY requirements.txt /djangobackend/
RUN pip install -r requirements.txt

# Copy project
COPY . /djangobackend/
这是我的
docker compose.yml
文件

version: '3.2'

services:
  db:
    image: postgres:10.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    build: .
    command: python /djangobackend/backend/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/djangobackend
    ports:
      - 8000:8000
    depends_on:
      - db

volumes:
  postgres_data:
version: '3.2'

services:
  db:
    image: postgres:10.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    build: ./djangobackend
    command: python /djangobackend/backend/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/djangobackend
    ports:
      - 8000:8000
    depends_on:
      - db # it means, it will execuate after db is done
  frontend:
    build: ./reactfrontend
    command: npm run build
    volumes:
      - .:/reactfrontend
    ports:
      - "3000:3000"
    depends_on:
      - web

volumes:
  postgres_data:
最重要的是工作正常

后来,我尝试将以下反应dockerize:

Dockerfile
如下:

# Pull base image
FROM python:3

# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory, we can name it whatever we want
WORKDIR /djangobackend

# Install dependencies
# Copy requirement file from the docker workdir we defined named djangodocker
COPY requirements.txt /djangobackend/
RUN pip install -r requirements.txt

# Copy project
COPY . /djangobackend/


# Use an official node runtime as a parent image
FROM node:8

WORKDIR /reactfrontend/

# Install dependencies
COPY package.json yarn.lock /reactfrontend/

RUN yarn

# Add rest of the client code
COPY . /reactfrontend/

EXPOSE 3000

CMD npm start
这是我的
docker compose.yml
文件

version: '3.2'

services:
  db:
    image: postgres:10.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    build: .
    command: python /djangobackend/backend/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/djangobackend
    ports:
      - 8000:8000
    depends_on:
      - db

volumes:
  postgres_data:
version: '3.2'

services:
  db:
    image: postgres:10.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    build: ./djangobackend
    command: python /djangobackend/backend/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/djangobackend
    ports:
      - 8000:8000
    depends_on:
      - db # it means, it will execuate after db is done
  frontend:
    build: ./reactfrontend
    command: npm run build
    volumes:
      - .:/reactfrontend
    ports:
      - "3000:3000"
    depends_on:
      - web

volumes:
  postgres_data:
有人能告诉我上面的代码有什么问题吗

我已经成功运行了命令
docker build。
但是如果我运行
docker compose.yml
,那么它会抛出错误:
错误:build path/home/pyking/Desktop/drdn/djangobend或者不存在,或者不可访问,或者不是有效的URL。

当我在react的docker文件中添加一些代码时,我不明白为什么会抛出这个错误,但它不会抛出错误。如果我不为react添加代码,有人能帮我将django react应用程序dockerize吗

  web:
    build: ./djangobackend
    command: python /djangobackend/backend/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/djangobackend
由于Docker compose中的
而发生错误

复制项目时

COPY . /djangobackend/
在Docker文件中,然后说明为什么需要在Docker compose中添加

删除Docker组件中的卷

或者更新脚本的路径,该路径可能是

/djangobackend/djangobackend/backend/manage.py 

当您在docker compose中使用with
进行复制时

是否尝试使用
docker compose-up--build
?否,docker compose-up