In this exercise you will refresh your Docker skills.
Open the exercise 1 folder templates/1
.
Open the Dockerfile that is located in it.
Describe each build instruction within that Dockerfile with a comment (a line starting with #
) above the instruction.
Focus on the Docker commands instead of the others. For example, describe what the RUN command does instead of npm install.
In this exercise, you will learn the difference and benefits of using multi-stage builds.
Open the exercise 2 folder templates/2
.
You may find a hello.go
and a Dockerfile
.
The go file just prints "Hello world".
Open the Dockerfile and make sure you understand what it does.
Try to build the image, run and inspect it. The goal is to figure out the size of the built container.
After you have found the size, change the Dockerfile to use multi-stage builds. The Dockerfile itself contains some hints on how to achieve that. Rebuild the image and compare the size to the original container.
What other benefits can you think of when using multi-stage containers?
Open the exercise 3 folder templates/3
.
The small python program you see, just prints the files from a directory you give as a parameter.
Open the Dockerfile in the folder. You can see that there are comments describing what the direct line under it does. There is also a small python file, which just prints all files of the directory given in the parameter.
Try to implement the Dockerfile and get it to run. If successfully built and ran, you should see some output in your console.
You can find the solutions here: solutions/
.
There are two possibilities to clean up the images after the exercises.
The first one is to list all images and use the rmi docker command.
docker images -a
docker rmi <image>
For the second one Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):
docker system prune
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:
docker system prune -a