简体   繁体   English

Docker在构建映像时找不到文件

[英]Docker cannot find file when building the image

This is my Dockerfile 这是我的Dockerfile

FROM python:3.6-slim

COPY app/ /app

EXPOSE 8000

RUN cd /app/
RUN pip install -r requirements.txt

WORKDIR /app/project/

RUN python manage.py makemigrations
RUN python manage.py migrate
RUN export DJANGO_SETTINGS_MODULE="project.settings"

CMD [ "python", "manage.py", "server"]

When I try to build it, it fails saying that it can't find the requirements.txt inside the app folder. 当我尝试构建它时,它无法说它找不到app文件夹中的requirements.txt。

When you do 当你这样做

RUN cd /app/
RUN pip install -r requirements.txt

Docker will enter the /app/project, and then, will come back to the previous folder, then, the second command will fail. Docker将进入/ app / project,然后,将返回上一个文件夹,然后,第二个命令将失败。 You have to use it like this: 你必须像这样使用它:

RUN cd /app/ && pip install -r requirements.txt

You can visualize how Django works when using Docker on this link that has a container running Django with a similar Dockerfile. 你可以想象Django在这个链接上使用Docker时的工作方式,该链接有一个运行Django的容器和类似的Dockerfile。

EDIT : To match a comment , you should replace the export line to an ENV, example: 编辑 :要匹配评论 ,您应该将导出行替换为ENV,例如:

ENV DJANGO_SETTINGS_MODULE project.settings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM