Issue
I'm running a
docker build -t $NAME -f Dockerfile.test .
command.
In my Dockerfile.test
I have at the end (I'm copying certain things to make everything work)
CMD["bin/bash", "-c", "bash /run-script.sh && bash /run-another-script.sh"]
When I look at my build stages in Jenkins, I can only see that everything passed ok, the
CMD /bin/bash -c bash /run-script.sh && bash /run-another-script.sh
was executed, and since I'm running a sonarqube scan in these scripts, I can see in my sonarqube that a scan happened (which is ok).
But since I'm running PHP unit tests in the scripts, I'm a bit suspicious that this part, because in the Jenkins this was done very quickly (on my local computer running unit testing with coverage report takes ~20min), failed, or didn't run as it should.
So I'd like to see the output of these scripts (run-script.sh
and run-another-script.sh
) to be sure that everything works as intended.
I've heard that docker won't show the output of the scripts that write/delete lines in the terminal, so this might be the reason (I'm guessing ofc).
Is there a way to show the output?
Solution
I think you are confusing RUN
and CMD
.
RUN
-commands are executed during the build (docker build
), CMD
-commands are executed when you start the container (docker run
).
To be certain I have written a small test:
Using CMD
$ docker build -t cmdtest -<<EOF FROM centos:7
RUN echo "echo script1" > script1.sh RUN echo "echo script2" > script2.sh
CMD ["bin/bash", "-c", "bash /script1.sh && bash /script2.sh"] EOF
does not print anything, because not executed. However, prints at docker run
:
$ docker run cmdtest
> script1
> script2
Using RUN
$ docker build -t cmdtest -<<EOF FROM centos:7
RUN echo "echo script1" > script1.sh RUN echo "echo script2" > script2.sh
RUN ["bin/bash", "-c", "bash /script1.sh && bash /script2.sh"] EOF
Sending build context to Docker daemon 2.048 kB ... Step 4/4 : RUN bin/bash -c bash /script1.sh && bash /script2.sh ---> Running in 7aab2725ed25
script1 script2 ---> 8ca71d1c67e8
prints at build-time.
Answered By - Fabian Braun