简体   繁体   中英

File not found from Dockerfile, docker-compose

I have these codes in my 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

When I called docker-compose build it returns /bin/sh: 1: requirements.txt: not found . Despite I have load the necessary volume in my docker-compose.yml. I am sure that requirements.txt is in ./

  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

How can I solve this problem?

Before running RUN pip install -r requirements.txt , you need to add the requirements.txt file to the image.

...
ADD requirements.txt requirements.txt

RUN pip install -r requirements.txt
...

For a sample on how to dockerize a django application, check https://docs.docker.com/compose/django/ . You need to add the requirements.txt and the code to the image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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