Why is git clone failing when I build an image from a dockerfile?
FROM ansible/ansible:ubuntu1604 MAINTAINER myname RUN git clone http://github.com/ansible/ansible.git /tmp/ansible RUN git clone http://github.com/othertest.git /tmp/othertest WORKDIR /tmp/ansible ENV PATH /tmp/ansible/bin:/sbin:/usr/sbin:/usr/bin:bin ENV PYTHONPATH /tmp/ansible/lib:$PYTHON_PATH ADD inventory /etc/ansible/hosts WORKDIR /tmp/ EXPOSE 8888
When I build from this dockerfile, I get Cloning into /tmp/ansible and othertest in red text (I assume is an error). When I then run the container and peruse around, I see that all my steps from the dockerfile built correctly other than the git repositories which are missing.
I can’t figure out what I’m doing wrong, I’m assuming its a simple mistake.
sudo docker build --no-cache -f Dockerfile .
sudo docker run -I -t de32490234 /bin/bash
One Solution collect form web for “Why is git clone failing when I build an image from a dockerfile?”
The short answer:
Put your files anywhere other than in
/tmp and things should work fine.
The longer answer:
You’re basing your image on the
ansible/ansible:ubuntu1604 image. If you inspect this image via
docker inspect ansible/ansible:ubuntu1604 or look at the Dockerfile from which it was built, you will find that it contains a number of volume mounts. The relevant line from the Dockerfile is:
VOLUME /sys/fs/cgroup /run/lock /run /tmp
That means that all of those directories are volume mount points, which means any data placed into them will not be committed as part of the image build process.
Looking at your
Dockerfile, I have two comments unrelated to the above:
You’re explicitly setting the
PATHenvironment variable, but you’re neglecting to include
/bin, which will cause all kinds of problems, such as:
$ docker run -it --rm bash docker: Error response from daemon: oci runtime error: exec: "bash": executable file not found in $PATH.
WORKDIRtwice, but the first time (
WORKDIR /tmp/ansible) you’re not actually doing anything that cares what directory you’re in (you’re just setting some environment variables and copying a file into