jz22
jz22

Reputation: 2638

How to use RUN clone git in dockerfile

Instead of using the ADD or COPY command I would like the docker image to download the python script (aa.py) that I want to execute from my git. In mygit there is only one file called aa.py.

This doesn't work:

FROM python:3

RUN git clone https://github.com/user/mygit.git

CMD [ "python3", "./aa.py" ]

Error message:

ERR /usr/local/bin/python: can't open file './aa.py': [Errno 2] No such file or directory

Upvotes: 5

Views: 5817

Answers (3)

Renjith Thankachan
Renjith Thankachan

Reputation: 4336

Problem here is aa.py file is in your current working directory

change the Dockerfile content to

FROM python:3
RUN git clone https://github.com/user/mygit.git
WORKDIR mygit
CMD [ "python3", "./aa.py" ]

OR

FROM python:3
RUN git clone https://github.com/user/mygit.git
CMD [ "python3", "mygit/aa.py" ]

Upvotes: 3

Iman
Iman

Reputation: 1297

The best solution is to change docker working directory using WORKDIR. So your Dockerfile should look like this:

FROM python:3
RUN git clone https://github.com/user/mygit.git
WORKDIR mygit
CMD [ "python3", "./aa.py" ]

Upvotes: 7

kstromeiraos
kstromeiraos

Reputation: 5027

Your problem is that CMD instruction can't find file aa.py.

You have to specify complete path to your aa.py which, if you didn't change the working directory will be /project_name/aa.py.

Upvotes: 1

Related Questions