0

I have created a docker file with the following:

    FROM python:3.9.2
MAINTAINER KSMC
RUN apt-get update -y && apt-get install -y python3-pip python-dev

WORKDIR /Users/rba/Documents/Projects/DD/DD-N4

RUN pip3 install -r requirements.txt

ENTRYPOINT ["python3"]
CMD ["main.py"]

My python code is in main.py , my python version is 3.9.2 and all my python code, requirements.txt and docker file are in the location /Users/rba/Documents/Projects/DD/DD-N4. Upon trying to create docker image using:

docker build -t ddn4image .

I am getting the following error:

#8 1.547 ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' ------ executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 1

Can someone point out what is causing this?

RB17
  • 356
  • 1
  • 8
  • 26

1 Answers1

2

You forgot to do a COPY statement.

Before you run RUN pip3 install -r requirements.txt, just put the following line

COPY . .

You need to do this because your local files need to be copied into the docker image build, so when your container is created, the files will exists on it.

Read the docs about COPY at docker docs.

Hint

Remove the ENTRYPOINT statement and use

CMD ["python3", "main.py"]

Here it is a good explanation about ENTRYPOINT and CMD difference.

Eduardo Coltri
  • 506
  • 3
  • 8
  • Upon making changes per your suggestion, I am getting the following error for pip still: – RB17 Mar 15 '21 at 19:41
  • This is the error I am gettiing: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1 – RB17 Mar 15 '21 at 20:22
  • I saw that are you running as `pip`, did you tried as `pip3`? – Eduardo Coltri Mar 15 '21 at 20:26
  • 1
    I tried using both. There seemed to be some incompatibility with pyodbc on the requirement.txt. It ran fine when I removed the pyodbc from requirements.txt. – RB17 Mar 16 '21 at 13:29
  • Right, see if this [question](https://stackoverflow.com/questions/46405777/connect-docker-python-to-sql-server-with-pyodbc) helps you about the pyodbc problem. – Eduardo Coltri Mar 16 '21 at 14:27