从Dockerfile,docker-compose找不到文件

我在我的Dockerfile中有这些代码。

FROM python:3 # Create user named "airport". RUN adduser --disabled-password --gecos "" airport # Login as the newly created "airport" user. RUN su - airport # Change working directory. WORKDIR /home/airport/mount_point/ # Install Python packages at system-wide level. RUN pip install -r requirements.txt # Make sure to migrate all static files to the root of the project. RUN python manage.py collectstatic --noinput # This utility.sh script is used to reset the project environment. This includes # removing unecessary .pyc and __pycache__ folders. This is optional and not # necessary, I just prefer to have my environment clean before Docking. RUN utility_scripts/utility.sh 

当我调用docker-compose build它时,返回/bin/sh: 1: requirements.txt: not found 。 尽pipe我已经在docker-compose.yml中加载了必要的卷。 我相信requirements.txt是在./

  web: build: context: ./ dockerfile: Dockerfile command: /home/airport/mount_point/start_web.sh container_name: django_airport expose: - "8080" volumes: - ./:/home/airport/mount_point/ - ./timezone:/etc/timezone 

我怎么解决这个问题?

在运行RUN pip install -r requirements.txt ,需要将requirements.txt文件添加到映像中。

 ... ADD requirements.txt requirements.txt RUN pip install -r requirements.txt ... 

有关如何dockerize django应用程序的示例,请查看https://docs.docker.com/compose/django/ 。 您需要将requirements.txt和代码添加到图像中。