Containerization with Docker
- By Dawid Borycki
- 2/25/2026
- Why use containers?
- What is Docker?
- Running multiple containers
- Summary
What is Docker?
Docker is a renowned open platform for automating and deploying applications as portable, self-sufficient containers that can run either in the cloud or on-premises. The only requirement is that the given machine must provide a Docker host, which serves as the containerization manager and runtime. Docker is also the name of the company that promotes and develops this containerization technology.
Developers can use Docker Desktop on Windows, Linux, or macOS. This tool includes a single-node Kubernetes cluster, which developers can use for local deployments and testing.
Docker is implemented in the Go programming language and employs namespaces technology to provide an isolated workspace, the container. These namespaces are used to isolate running containers. Specifically, a running container has access only to its associated set of namespaces and cannot access the namespaces of other containers. In virtual machines, such isolation is achieved with a hypervisor.
Architecture
The Docker architecture, depicted in Figure 3-3, uses a client-server approach in which a Docker client communicates with the Docker daemon running on the server (Docker Host). The Docker daemon is a background process (server) that listens to requests from the client. These requests are usually sent using the Docker Command Line Interface (Docker CLI) or the remote API.
FIGURE 3-3 Docker architecture.
The major Docker CLI commands include:
docker pull Downloads a container image from a container registry, which is a service that can contain multiple repositories for container images, like Git. There are local and remote repositories, so the docker pull command (like git pull) downloads an image from a remote repository.
docker push Sends a local container image to a remote repository.
docker build Builds a container image by turning the application, its dependencies, and its configuration into a self-sufficient container image, which can then be sent to a remote repository or used to run the container locally.
docker run Creates and runs a container instance from the specified container image. This command first tries to locate the selected container image in the local repository. If the container is unavailable locally, the command pulls the image from the remote repository hosted by the container registry.
By default, Docker uses Docker Hub as the container registry, where you can create public or private repositories. Private repositories are used for images that you do not want to share with others.
Notably, the Docker client and daemon can run on the same machine, as is the case when Docker Desktop is installed.
How to pull and run a container
To use the Docker CLI to pull a container image and run it on a local Docker host, you must first ensure that Docker Desktop is running (see Figure 3-4).
FIGURE 3-4 Docker Desktop.
The icon in the bottom-left corner indicates the status of the Docker Engine (which includes both the daemon and client). The icon should be green. If it is red, you might want to restart the engine or troubleshoot using the Docker documentation.
After ensuring that Docker is up and running, it is helpful to familiarize yourself with the available tabs in Docker Desktop:
Containers Shows the list of running containers. When you start Docker Desktop for the first time, this list will be empty. The Containers tab will display instructions on how to run a container.
Images Includes the list of images in your local and remote repositories.
Volumes Displays the list of volumes, which can be attached to containers to provide non-volatile storage.
Builds Contains the list of builds and builder configurations.
Dev Environments Enables you to manage Dev Environments, which you can use to create reusable environments for developers that contain all the tools they need.
Docker Scout Enables advanced analysis of Docker images.
You can access the same lists through the Docker CLI.
Now, back to the task at hand: To pull the container image with the ASP.NET Core sample app, open the command line or terminal, and then type:
docker pull mcr.microsoft.com/dotnet/samples:aspnetapp
The command downloads the Docker image from the .NET repository hosted on Microsoft's public container registry (see Figure 3-5). Note the last string after the colon (aspnetapp). This is the image tag, an additional label you can apply to images and use for versioning. Docker will use the most recent version of the tag if you do not specify an explicit tag.
FIGURE 3-5 Pulling a Docker image.
By analyzing the output of the docker pull command, you can see that the pull operation is composed of several steps, because this specific image contains multiple layers. Docker uses layers to optimize container builds and transfers, as detailed in the Dockers Layers Guide (docs.docker.com/build/guide/layers).
To verify that the image was downloaded, type:
docker images
The command lists the images available in your local repository. If you return to Docker Desktop and click the Images tab, you will see the same image (as shown in Figure 3-6).
FIGURE 3-6 A list of local images.
To run a container, use the Docker CLI. In the command line or terminal, type (see Figure 3-7):
docker run -p 80:8080 --name aspnet-sample-app mcr.microsoft.com/dotnet/↲
samples:aspnetapp
FIGURE 3-7 Running a container.
This command runs the container named aspnet-sample-app using the --name parameter. If you omit this parameter, Docker will assign a random name to the container. The running container will be accessible from the host on port 80, which will be mapped to port 8080 inside the container. This mapping is configured using the -p parameter. The first value is the host port, and the second is the container port. Finally, you provide the image to spin up the container. If the image was not pulled beforehand, the docker run command will pull it for you as shown earlier in Figure 3-6.
The container is up and running in the background. To access the application, open a web browser and type localhost in the address bar. The application will appear as shown in Figure 3-8.
FIGURE 3-8 Running a containerized ASP.NET Core application.
How to manage containers
To see a list of running container instances, go to Docker Desktop and click Containers. The Containers tab lists each running container’s name (aspnet-sample-app) and identifier (19991a32237b), as shown in Figure 3-9. It also displays the name of the image used to spin up the container, the container’s status, port mapping, uptime, and additional actions. You can use these actions to stop, pause, or restart the container.
FIGURE 3-9 Docker Desktop showing a containerized ASP.NET Core application.
Additionally, if you click the ellipsis under Actions and select View Details, you will see the app’s output and the container’s stats, such as CPU and memory usage. From this view, click Exec to access the terminal inside the running container. From here, you can invoke any command available in the container, for example, top (see Figure 3-10). The available commands will depend on the base image used to create the container and the tools installed within it.
FIGURE 3-10 Connecting to a terminal of the running container.
Importantly, you can achieve similar results using the Docker CLI. Specifically, to get a list of running containers, use the command:
docker ps
To connect to a terminal inside a running container named aspnet-sample-app, you can use the following command:
docker exec -it aspnet-sample-app /bin/sh
This command executes /bin/sh inside the running container. Note the usage of the -it flag, which indicates that the command should be invoked in interactive mode, giving you access to the standard input for the container (here, a command line or terminal).
How to remove a container
When you launch a container, the command line displays the app’s output running in the container. If you close the output by pressing Ctrl+C (Windows) or Command+C (macOS), the application running in the container will stop and the container’s status will change to Exited. Consequently, you cannot re-run the container with the same name. Therefore, you need to delete the aspnet-sample-app container, either by clicking the Trash icon in Docker Desktop or by typing:
docker rm aspnet-sample-app
Finally, Docker Desktop enables you to run a local image using the UI. To do this, open the Images tab of Docker Desktop, select a container image, and click its Run icon under Actions (Figure 3-6). In the Run A New Container window that appears, you configure the container’s name, port mapping, volumes, and more, as shown in Figure 3-11.
FIGURE 3-11 Running a container.
