Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: October 14, 2024
Podman, a daemon-less container engine, provides many of the same functionalities as Docker, including pulling images from container registries. While Docker Hub is a widely used registry for hosting container images, accessing Docker Hub images using Podman requires a few specific configurations.
In this tutorial, we’ll explore different steps for pulling official images from Docker Hub using Podman. We’ll use the Ubuntu Linux distribution to illustrate the commands in this tutorial.
First, we need to update the package list and install Podman using apt:
$ sudo apt update
$ sudo apt install podman
The last command installs Podman and its dependencies. After installation, we can verify that Podman is installed by checking its version:
$ podman --version
podman version 5.2.3
This displays the installed version of Podman on the system. In particular, it confirms Podman’s installation.
Before diving into pulling official Docker Hub images, it’s essential to understand the basic Podman command structure. We use the podman pull command to pull an image:
$ podman pull <image_name>
The command searches for the specified image in the default registries configured in Podman. However, if we don’t specify a tag, Podman pulls the latest version of the image by default.
When pulling official images from Docker Hub, we need to specify the complete registry URL to avoid errors like invalid reference format or 404 not found. Podman interacts with registries using fully qualified image names. Furthermore, these image names include the registry domain, image path, and tag (if needed).
For example, let’s pull the official Postgres image from Docker Hub:
$ podman pull docker.io/library/postgres
Trying to pull docker.io/library/postgres:latest...
Getting image source signatures
...|
Copying blob 28b27d53d86b done |
Copying blob bfc263366b3f done |
Copying blob e5ff51eeda62 done |
Copying config f0dfc903a6 done |
Writing manifest to image destination
f0dfc903a6636f2648135b399caf4dcd9f5f595b485672ca96cd91d9fa48110c
This command specifies the domain name and image path:
It retrieves the official PostgreSQL image from the library namespace on Docker Hub. Specifically, this enables us to run PostgreSQL in a containerized environment.
We can also configure Podman to use Docker Hub as a default registry for unqualified image names. Consequently, this removes the need to specify docker.io/library/ when pulling an image.
To do this, we modify Podman’s configuration file to include Docker Hub in its unqualified search registries.
First, let’s open the Podman configuration file for editing:
$ sudo nano /etc/containers/registries.conf
Next, we add Docker Hub to the list of unqualified search registries:
unqualified-search-registries = ["docker.io"]
After making this change, we can simply use shorter commands to pull images from Docker Hub.
For example, let’s pull the official Nginx image from Docker Hub:
$ podman pull nginx
Resolving "nginx" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/nginx:latest...
...
Copying blob 55af3c8febf2 done |
Copying blob 4b563e5e980a done |
Copying blob 85177e2c6f39 done |
Copying config 7f553e8bbc done |
Writing manifest to image destination
7f553e8bbc897571642d836b31eaf6ecbe395d7641c2b24291356ed28f3f2bd0
The command pulls the nginx image from Docker Hub without needing the fully qualified reference.
Additionally, we can also use Podman to pull specific versions of images by specifying an image tag. The tag typically represents the version of the software inside the container.
For example, let’s pull a specific version of the Python image:
$ podman pull docker.io/library/python:3.10
Trying to pull docker.io/library/python:3.10...
Getting image source signatures
...
Copying blob 01272fe8adba done |
Copying blob 2503de423c42 done |
Copying blob fddd6c71e764 done |
Copying config c780c1edc8 done |
Writing manifest to image destination
c780c1edc88f3c7244e1b75cae5a7f8df8cf33461e25d67e916dc76a3218b2cf
In this example, we pull version 3.10 of the Python image instead of the default latest.
In addition to unqualified search registries, we can use Podman to define short-name aliases for registries. Furthermore, this feature is useful when we frequently pull images from a particular registry and want to avoid typing the full registry URL.
For example, to create a short name alias, we can edit the shortnames.conf file:
$ nano /etc/containers/registries.conf.d/shortnames.conf
Now, let’s say we often pull Oracle Linux images from the Oracle container registry. We can add the following entry to the shortnames.conf file:
[aliases]
"orclinx" = "container-registry.oracle.com/os/oraclelinux"
Next, instead of typing the full registry path, we can use the alias to pull Oracle Linux images:
$ podman pull orclinx
Resolved "orclinx" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull container-
...
Copying config d788eca028 done |
Writing manifest to image destination
d788eca028a0f49b6bc70b251c8535b16ee5bd94e0ab375ca8f3a923e6ce4281
This feature saves time and ensures consistency when working with multiple registries.
In this article, we’ve explored how to install Podman and pull official images from Docker Hub. In particular, we examined several methods such as using fully qualified names, unqualified search registries, and short name aliases.
These features streamline the process of managing container images, making Podman a powerful and flexible alternative to Docker.