Building images
Docker can be treated as a useful tool to run applications; however, the real power lies in building own Docker images that wrap the programs together with the environment. In this section, we will see how to do this using two different methods, the Docker commit
command and the 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 16.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 the
ubuntu:16.04
and connect it to its command line:
$ docker run -i -t ubuntu:16.04 /bin/bash
We've pulled the ubuntu:16.04
image and 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...