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?
To do so, you need to navigate to the correct folder and then run the command git init , which will create a new empty Git repository or reinitialize an existing one.
The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
change the "RUN cd /cloned-qt/" command to "WORKDIR cloned-qt" and it will work as expected
Each time you do a RUN
, docker creates a new temporary container to run it therefore command like cd has no effect.
Do
WORKDIR /cloned-qt/
instead of
RUN cd /cloned-qt/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With