Building Docker images
In this section, we will see how to build Docker images using two different methods: the docker
commit
command and a Dockerfile automated build.
docker commit
Let's start with an example and prepare an image with the Git and JDK toolkits. We will use Ubuntu 20.04 as a base image. There is no need to create it; most base images are available in the Docker Hub registry. Proceed as follows:
- Run a container from
ubuntu:20.04
and connect it to its command line, like this:$ docker run -i -t ubuntu:20.04 /bin/bash
We've pulled the ubuntu:20.04
image, run it as a container, and then called the /bin/bash
command in an interactive way (-i
flag). You should see the Terminal of the container. Since containers are stateful and writable, we can do anything we want in its Terminal.
- Install the Git toolkit, as follows:
root@dee2cb192c6c:/# apt-get update root@dee2cb192c6c...