In this section, we will see how to do this using two different methods: the Docker commit
command and the Dockerfile automated build.
Let's start with an example and prepare an image with the Git and JDK toolkit. We will use Ubuntu 18.04 as a base image. There is no need to create it; most base images are available in the Docker Hub registry:
- Run a container from
ubuntu:18.04
and connect it to its command line:
$ docker run -i -t ubuntu:18.04 /bin/bash
We've pulled the ubuntu:18.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:
root@dee2cb192c6c:/# apt-get update root@dee2cb192c6c:/# apt-get install -y git
- Check whether the Git toolkit is installed:
root@dee2cb192c6c:/# which git /usr/bin/git
- Exit the container:
...