Skip to main content
Welcome to this comprehensive guide on container management and configuration. In this article, we explore how containers simplify application deployment and migration by encapsulating everything—daemons, configuration files, logs, and databases—in a single, portable unit. Unlike traditional setups (e.g., a conventional MariaDB installation where components are scattered in various directories), containerized applications streamline the process of moving applications between different systems.

Installing Podman to Emulate Docker

In some environments, such as CentOS Stream 8, Docker might not have official support. In these cases, you can install Podman, which offers a Docker-compatible command-line interface. To install Podman using the dnf package manager, execute the following command:
After installation, Podman allows you to use familiar Docker commands as it seamlessly translates them under the hood. The installation output might resemble the following:

Configuring Podman’s Default Registry

Podman’s configuration file is located at /etc/containers/registries.conf. Open it using your preferred text editor (for example, vim):
Find the line that configures unqualified search registries:
Comment out the above line and add the following to set docker.io as the default registry:
If you receive a message about emulating the Docker CLI with Podman, you can disable this behavior by creating a specific file:

Working with Images

Searching for an Image

For this guide, we will use the popular Nginx web server as an example. To locate available Nginx images, run:
The output may include entries such as:
The official image, often referred to as docker.io/library/nginx, is well-supported and highly rated.

Pulling an Image

To pull the official Nginx image, use its fully qualified name:
For convenience, you can also use the short form:
To pull a specific version (for instance, version 1.20.2), run:
After pulling an image, you can list the available images with:
Example output:
If you wish to remove a specific version, execute:
Images can also be referenced by their IMAGE ID, using just enough characters to uniquely identify them.

Running and Managing Containers

Creating and Attaching to a Container

To create and run a new container using the Nginx image, use:
This command creates a container and attaches your terminal to its output. If you find that the container’s logs (for example, startup messages from /docker-entrypoint.sh) continuously appear, press Ctrl+C to detach and terminate the container. To run the container in detached mode, use the -d option:
This command returns a hexadecimal container ID and allows the container to run in the background.

Listing, Stopping, and Removing Containers

To list active containers, run:
For a complete list of containers (including those that have exited), use:
To stop a container, specify its container ID or assigned name. For example, to stop a container named interesting_mcclintock:
After stopping the container, remove it with:
If the container is running and you wish to force its removal, use:

Removing Images

If you try to remove an image that is currently in use, Docker will produce an error:
Example error message:
To force the removal of an image (this will stop and remove any dependent containers), add the --force option:

Advanced: Naming Containers and Port Mapping

For improved container management, you can assign custom names and set up port mapping between the host and container. To run Nginx in a container named mywebserver with host port 8080 mapped to container port 80, use:
This configuration directs any connection to port 8080 on your machine to port 80 inside the container. To test the setup, you can use netcat:
After connecting, type the following command:
Then press Enter. This simulates a browser request to Nginx, displaying the default HTML page. Press Ctrl+C to exit the netcat session. Note: Mapping to privileged ports (ports below 1024) requires root privileges. For example, to map host port 80 to container port 80, use:

Getting Help

For detailed information about any Docker command, append the --help option. For example:
Or to get help for a specific command like docker rm:
Below is an example of help output for Podman’s container removal command:

Conclusion

This guide demonstrated the key steps in managing and configuring containers on Linux using Docker and Podman. We covered installing Podman, configuring its default registry, working with images, running containers in both attached and detached modes, and advanced topics like port mapping and naming containers. Continue exploring these concepts to elevate your container management skills. Happy containerizing!

Watch Video