Search code examples
gitdockerdockerfileclone

Docker build image complain about: fatal: not a git repository (or any of the parent directories): .git


I am using this Dockerfile content:

FROM ubuntu:18.04
RUN apt-get update 
RUN apt-get install git -y
RUN git clone https://code.qt.io/qt/qt5.git /cloned-qt    
RUN cd /cloned-qt/   
RUN git checkout 5.11
RUN git pull

Once I run my build image command:

sudo docker build -t qt5.11-auto:v1 .

I get this error message:

Sending build context to Docker daemon  4.608kB
Step 1/10 : FROM ubuntu:18.04
 ---> ea4c82dcd15a
Step 2/10 : RUN apt-get update
 ---> Using cache
 ---> 60e7c61ea78c
Step 3/10 : RUN apt-get install git -y
 ---> Using cache
 ---> 50a4def0607e
Step 4/10 : RUN git clone https://code.qt.io/qt/qt5.git /cloned-qt
 ---> Using cache
 ---> 97fb8ab6dc15
Step 5/10 : RUN cd /cloned-qt/
 ---> Running in 9be03fba40fa
Removing intermediate container 9be03fba40fa
 ---> 130bc457eb66
Step 6/10 : RUN git checkout 5.11
 ---> Running in 35de823fdf9c
fatal: not a git repository (or any of the parent directories): .git

After this failed step, when I run the container and execute the same commands I manage to run them successfully. what seems to be the reason that the docker build fail to run the "git checkout" command but when running it inside the container it works?


Solution

  • change the "RUN cd /cloned-qt/" command to "WORKDIR cloned-qt" and it will work as expected