Docker Containers

Understand Docker containers, how to run Docker images, and how to create a Docker image from an existing Docker container.

Docker container

Docker, Inc. is a founding member of the Open Container Initiative (OCI)—an organization that provides an open governance structure for the sole purpose of developing open industry standards for container formats and runtimes.

Docker, Inc. provided the initial codebase that served as the foundation for container runtime specification. As a result, what we learn about Docker containers in this lesson is applicable to other container runtimes.

As mentioned earlier, a Docker container is an instance of a Docker image. We can think of Docker images as the blueprint of Docker containers. The primary distinction between containers and images is that containers have a thin writable layer where data is stored.

When we create a new container, a thin writable layer is added on top of the Docker image’s underlying immutable layers. All changes such as creating a new file, modifying existing files, or deleting a file are stored on this writable layer.

This writable layer allows us to run multiple containers from a single image because each container has its own unique writable layer that is independent of others even if they share the same image.

In the previous lesson, we defined the Docker architecture as a client-server architecture, with the Docker daemon serving as the brain and the Docker CLI serving as the client used to interact with the server. It makes no difference if the server and client aren’t on the same physical machine. Therefore, when we talk about Docker commands, we’re talking about the Docker CLI.

Run Docker containers

We’ve spent some time discussing Docker images, but the most important part is putting Docker images to use by running them. This is exactly what we do in this lesson.

When we find ourselves on an alleged Docker host, one of the first things we should do is to check whether Docker is running on the host.

The simplest way to check is to use the following command:

Press + to interact
docker version

The output should look like this:

Press + to interact
Client:
Cloud integration: 1.0.2
Version: 20.10.1
API version: 1.41
Go version: devel +37a32a1833 Thu Dec 3 21:34:39 2020 +0000
Git commit: 831ebeae96
Built: Wed Dec 16 02:33:22 2020
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: f001486

If Docker is running on the host, we receive a response similar to the one shown above. Otherwise, we get a different response, which could be a result of the Docker server not running on the host. It could also be that we don’t have permission to interact with the Docker host.

If Docker is already running on the host, the simplest way to start or run a ...