使用docker-compose的Dockerising Django应用出现问题 [英] Issue with Dockerising Django app using docker-compose
问题描述
我是Docker的新手,我想将Django应用作为容器进行dockerise。
I am new to Docker and I want to dockerise the Django app to run as a container. Followed as below.
这是 Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
这是 docker-compose.yml
conf
version: '3'
networks:
mynetwork:
driver: bridge
services:
db:
image: postgres
ports:
- "5432:5432"
networks:
- mynetwork
environment:
POSTGRES_USER: xxxxx
POSTGRES_PASSWORD: xxxxx
web:
build: .
networks:
- mynetwork
links:
- db
environment:
SEQ_DB: cath_local
SEQ_USER: xxxxx
SEQ_PW: xxxxx
PORT: 5432
DATABASE_URL: postgres://xxxxx:xxxxx@db:5432/cath_local
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
在我的docker shell上,如果我从y运行ls命令,则指向Dockerfile目录路径,我看到manage.py文件,但是如果我运行:
well on my docker shell i point to Dockerfile directory, if i run an ls command from y path i see the manage.py file, but if i run:
docker-compose up
我收到此错误:
web_1 | python:无法打开文件'manage.py':[错误2]没有这样的文件或目录
core_web_1以代码2退出
web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory core_web_1 exited with code 2
为什么我的应用程序找不到与 docker-compose up命令相同位置的manage.py文件?
Why my app don't find manage.py file that is in the same position as the "docker-compose up" command is?
PS:否我运行docker-compose命令时会创建/ code文件夹。
PS: No /code folder is created when i run docker-compose command. Is it correct?
非常感谢
推荐答案
尝试像这样编辑Dockerfile:
try to edit your Dockerfile like this:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
并删除命令:python manage.py runserver 0.0.0.0:8000
从撰写
我假设 manage.py
在 / code /
文件夹,因为在 dockerfile
中有 WORKDIR / code
,然后将在构建阶段,文件将被复制到其中
I assumed that the manage.py
is in /code/
folder, since you have WORKDIR /code
in the dockerfile
then the server will be created in the build stage and the files will be copied to it
这篇关于使用docker-compose的Dockerising Django应用出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!