我有一个默认的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
型
1条答案
按热度按时间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