How to Use Podman to Search for an Image in the Registry?



When we talk about applications that we take and run in the container world, we call this an image, which we save somewhere and run for as long as we need it. We have a lot of places where we can find an image; we call these image registries.

We may have the image locally on our machine or in a specific place like the Internet (image repository or registry). Podman helps us deal with those registries. For example, we can search for a specific image in the image repository.

If you search for an image for httpd, what you can do is use the podman search command like this:

podman search httpd

Well, you didn't get anything, right? The command works fine, but what happens here is that Podman searches for an image called httpd, and because we just set up Podman, we don't have any images locally. Since we didn't configure the file for Podman to enable searching on the Internet, we get an empty search result. For this, we need to set the configuration file in order for the search to work!

Configure the Registry

Podman uses a config file that is located at the path /etc/containers/registries.conf. Podman uses this file whenever we pull or push an image to the registry. So, whenever we try to connect to a container registry, Podman uses this file.

If you open the file, you will see something like this ?


Instead of dealing with the default configuration, we can create a configuration for the user in the location $HOME/.config/containers/registries.conf that will hold our custom configuration.

First, create a directory inside the .config folder called containers.

Then, create a file called registries.conf inside this folder and start adding the configuration.

Note: Make sure you write the names correctly; if you misspell something, this will not work. The first thing that we're going to add is the registry that we will use with the search command. For now, just add one line of code ?

unqualified-search-registries = ['docker.io','ghrc.io','quay.io']

Now, what this line does is specify the registries that we need to use when we search for an image. In this example, we add the Docker registry (docker.io), the GitHub registry (ghcr.io), and the Red Hat container registry (quay.io). You can add whatever you want, for example, your company registry.

Now, whenever we do a podman search for a specific image, Podman will use this file and check for our image in the three repositories that we added in this configuration file.

If we do the search again for httpd, we should get a result like this ?


Httpd is provided by Apache Server, which is a popular web server, and 'd' stands for daemon. This command gives us the name and source on the right and a simple description of the container on the left.

Pull and Run a Container

After getting an idea of how to search for an image on the registry, let's learn how to pull a specific image and run the container. To download an image from the registry to the local machine, we use the command pull.

Using the same example that we did before, let's get this image ?


It's an image from Docker, and if you pay attention to the description, you may notice it says httpd:latest. We call this a tag, which defines the version of the image; in this case, it's the latest version. In some cases, we may need to specify the version that we need to install.

To download this image from the registry to our machine, we use the complete command ?

podman pull docker.io/publici/httpd

We use the command pull followed by the name of the image. In our case, the name is docker.io/publici/httpd.

You may have a question: why do I need to write the name like this docker.io/publici/httpd, instead of just using the name directly? Well, we can use the simple command pull httpd. This command will get the latest image from Docker Hub.

Behind the scenes, this command podman pull httpd is like this: podman pull docker.io/library/httpd.

Note: If we don't specify the repository, by default, it will be docker.io, and if we don't specify the namespace, it will be the namespace library.

In our case, we specify publici as a namespace, so we tell Podman where to look for the image directly.

In case you don't know where to search, using the default may be the best choice, as it contains trusted and official images that are generally maintained by the developers of the project. Note that in our case here, we didn't specify the version, so Podman will get the latest version for us.

Run the Command and Get the Image

Now let's run the command and get the image to our computer. When you run this, you should get an output like this indicating that you are downloading the image.


And it depends on the size of the image and your internet download speed it may take some time to download the image.

After the downloading is completed, you should see the downloaded images using the command:

podamn images 

Or the command podman images ps they do the same job, listing all images that you have.

The output will look like this ?


This shows some information about the image: the name, the size, the tag, and when it was created.

To get more information about a specific image, we can inspect it using the following command ?

podman inspect imageName

You can use either the image name or ID; both will work. This will show a bunch of information about the specific image.

For example, if we inspect the httpd image, we will get information like the image layers ?


An image consists of layers packed together. If we make new changes to this image, another layer will be added.

We can also get the port that is used. In this example, our httpd uses port 80.


Run a Container in Podman

After getting the image, it is now ready to be executed. To run a container in Podman, we use the command ?

Podman container run ImageName 

After you run a container, you can get the list of running containers using the command ?

Podman container

You should get something like this, indicating that the container is running ?


Conclusion

In this article, we discussed about a container engine called Podman, which we can use to create and manage images and containers.

Updated on: 2024-11-21T10:23:24+05:30

530 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements