Every instruction we set in the Dockerfile is going to be built as a separate, temporary image for the other instruction to build itself on top of the previous instruction.
There is a Dockerfile in the repo at /bootcamp/ch
apter06/debu
g
:
FROM alpine RUN ls -lha /home RUN ls -lha /vars CMD echo Hello world
Building the image using the following command:
docker image build
Gives you the following output:
So, there is an error in our Docker file. You may notice there is a line in the output which says --->5f828f86eaa4
this is actually an image file which was built following the successful execution of the RUN ls -lha /
home
line.
This means that we can launch a container using this image:
docker container run -it --name=debug 5f828f86eaa4 /bin/sh
We can then debug our application, which in this case is simple:
Debugging is a process of analyzing what's going on and it's different for every situation, but usually the way we start debugging is by trying to manually make the instruction that fail work manually and understand the error. When I get the instruction to work, I usually exit the container, update my Dockerfile and repeat the process until I have something working.
Notice that when the line which is causing the error is corrected (by supplying the correct line RUN ls -lha /var
) and we try the build again that Docker doesn't create a new image for the one step which was successful:
Once it has built the temporary image is removed and we are left with our final image:
That was quite a simple example, but it should give you an idea of how to debug a more complex Dockerfile.
3.149.26.31