Django dockerfile无法打开文件“/app/src/manage.py”:[Errno 2] No such file or directory

disho6za  于 2023-11-17  发布在  Docker
关注(0)|答案(1)|浏览(129)

我有一个默认的Django项目,我想Dockerize。我还想设置一个卷来移动src目录。当我创建容器时,我得到一个错误:python: can't open file '/app/src/manage.py': [Errno 2] No such file or directory

Dockerfile

FROM python:3.11
WORKDIR /app
ADD requirements.txt .
RUN pip install -r requirements.txt
RUN mkdir ./src
COPY ./src ./src
VOLUME /app/src
EXPOSE 8000
CMD ["python", "src/manage.py", "runserver", "0.0.0.0:8000"]

字符串

错误

$ docker build -t django-img .
$ docker run -v ./src:/app/src -p 8000:8000 django-img
python: can't open file '/app/src/manage.py': [Errno 2] No such file or directory

项目树结构

- .venv
- requirement.txt
- dockerfile
- src
-- component1
--- ...
-- src
--- .env
--- settings.py
--- urls.py
-- manage.py

jc3wubiy

jc3wubiy1#

您的路径在CMD ["python", "src/manage.py", "runserver", "0.0.0.0:8000"]中错误
“src/manage.py“应为“/app/src/manage.py”
WORKDIR /app在新镜像中创建该目录,并将您更改为新目录。因此,当您复制src时,您将其复制到/app。
https://docs.docker.com/engine/reference/builder/#workdir

相关问题