Docker Images Introduction
What is an Ubuntu Docker Container?
Ordinary software packages can often be installed in a variety of different types of environments that satisfy the given packaging system. However, these environments can be quite varied, such as including versions of language runtimes, system libraries, and other library dependencies that the software was not well tested with.
Docker containers address the inconsistencies that can arise in such a situation by encapsulating not only the software itself, but also much of the surrounding environment. Instead of installing and maintaining a collection of software packages, the user installs and maintains a single container. The user relies on the provider of the Docker container to perform the necessary software testing and maintenance updates. There is a rich ecosystem of Docker container providers thanks to how easy Docker makes it to create containers.
The “Open Container Initiative” (OCI) establishes standards for constructing Docker images that can be reliably installed across a variety of compliant host environments. Ubuntu’s implementation of OCI containers for Kubernetes is named “ROCKS”.
Ubuntu’s LTS Docker Image Portfolio provides OCI-compliant images that receive stable security updates and predictable software updates, thus reliably simplifying the maintenance of software containers.
Here’s a quick exploration of Ubuntu’s OCI Docker image. Spin up a container providing the Nginx software:
$ docker run -d --name nginx-container -e TZ=UTC -p 8080:80 ubuntu/nginx:1.18-20.04_beta Unable to find image 'ubuntu/nginx:1.18-20.04_beta' locally 1.18-20.04_beta: Pulling from ubuntu/nginx c1bf981888da: Pull complete 131ba4c4c06e: Pull complete 59fc0d1f2904: Pull complete de1589e6a236: Pull complete Digest: sha256:7f67198e894158efb3714f49e1818bff005518b9a8a2e923f19821200212efd2 Status: Downloaded newer image for ubuntu/nginx:1.18-20.04_beta d6445f7ec1a53b7167eb2f724fab6c3cc21bd4100846bcb896b4b845fd08c457
This container, named
nginx-container runs in an Ubuntu 20.04 LTS environment and listens for connections on local port 8080. Load the website up in your local web browser:
$ xdg-open http://localhost:8080 Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.
The container operates much like any other Ubuntu host. You can log into it as root via:
$ docker exec -it nginx-container /bin/bash
From here, you can examine logs or install packages from the archive normally. For example, if you’re attempting to debug network connections you might run:
root@abcd12345678:/# apt-get update && apt-get install -y iputils-ping net-tools root@abcd12345678:/# ifconfig | grep inet inet 192.168.192.1 netmask 255.255.240.0 broadcast 192.168.207.255 inet 127.0.0.1 netmask 255.0.0.0 root@abcd12345678:/# ping 192.168.192.2 -c1 | tail -n2 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.032/0.032/0.032/0.000 ms
Once you’re done exploring, shut the image down and delete it:
$ docker stop nginx-container $ docker rm nginx-container
A variety of other software containers are provided on Docker Hub, including documentation of supported customization parameters, and debugging tips.
Now, a single container like this one is marginally interesting, but the utility really shines when building a modular system of multiple containers working on concert. Let’s investigate that next.