Igor Simoes
Igor Simoes

Reputation: 41

Docker cannot find file when building the image

This is my 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.

Upvotes: 3

Views: 3520

Answers (1)

user7503126
user7503126

Reputation:

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. 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.

EDIT: To match a comment, you should replace the export line to an ENV, example:

ENV DJANGO_SETTINGS_MODULE project.settings

Upvotes: 6

Related Questions