从Dockerfile找不到文件,docker-compose

时间:2017-10-03 09:55:24

标签: docker 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。尽管我已经在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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

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

...
ADD requirements.txt requirements.txt

RUN pip install -r requirements.txt
...

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