Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 564
jz22 Avatar asked Jun 14 '17 10:06

jz22


People also ask

How do I clone in Docker?

To 'clone' a container, you'll have to make an image of that container first, you can do so by "committing" the container. Docker will (by default) pause all processes running in the container during commit to preserve data-consistency. Commit my_container as an image called my_container_snapshot , and tag it yymmdd .

What is run instruction in Dockerfile?

RUN - RUN instruction allows you to install your application and packages required for it. It executes any commands on top of the current image and creates a new layer by committing the results. Often you will find multiple RUN instructions in a Dockerfile.


1 Answers

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" ]
like image 65
Iman Avatar answered Oct 10 '22 09:10

Iman