Search code examples
gitdockerboot2dockergit-clone

Dockerfile 'RUN git clone' removes intermediate container


I using Boot2Docker on Windows 7 to build my developement environment with a Dockerfile. When i run docker build -t myimage dir/of/docker/file, then everything works fine until this line:

RUN git clone --verbose https://github.com/zsh-users/antigen ~/.antigen/antigen

The output of this line is:

Step 12 : RUN git clone --verbose https://github.com/zsh-users/antigen ~/.antigen/antigen
---> Running in 26cba91e912a
Cloning into '/root/.antigen/antigen'...
POST git-upload-pack (302 bytes)
---> e0012659884b
Removing intermediate container 26cba91e912a
Successfully built e0012659884b

The clone (of a public repository) is droped, the ~/.antigen/antigen isn't exists in the container. The "Cloning into..." is red, so i think there is something wrong with the command. But if i'm running it in the container's shell (opened by docker run -it myimage) it clones it.

Am i doing something wrong, or may i do some setup to use git clone in dockerfile? Here's the full content of it:

FROM debian:testing
MAINTAINER BimbaLaszlo

RUN apt-get update

RUN apt-get install -y curl

RUN apt-get install -y gcc g++ make
RUN apt-get install -y ctags
RUN apt-get install -y git

RUN apt-get install -y python python-pip python3 python3-pip

RUN apt-get install -y ruby ruby-dev
RUN gem install ripper-tags gem-ripper-tags
RUN gem install pry byebug

RUN apt-get install -y zsh
RUN git clone --progress --verbose https://github.com/zsh-users/antigen ~/.antigen/antigen

Solution

  • The color you see in red, is not caused by error. It's because git clone doesn't use STDOUT, we can verity it by following command:

    $ git clone --progress --verbose https://github.com/zsh-users/antigen > /dev/null
    Cloning into 'antigen'...
    POST git-upload-pack (255 bytes)
    remote: Counting objects: 1291, done.
    remote: Total 1291 (delta 0), reused 0 (delta 0), pack-reused 1291
    Receiving objects: 100% (1291/1291), 1.10 MiB | 900.00 KiB/s, done.
    Resolving deltas: 100% (688/688), done.
    Checking connectivity... done.
    
    $ git clone --progress --verbose https://github.com/zsh-users/antigen 2&> /dev/null
    

    In the first command, I redirected all STDOUT into /dev/null, we can still see the output. But in the second command, I redirected all STDERR into /dev/null, so we saw nothing.

    And in docker build, if any output is not in STDOUT, it will turn RED. That's it.

    So nothing is wrong with your Dockerfile.