How to get Started Deploying Containers with Podman

A person who develops on a Linux system using a dual-screen system.
Image: Esteban Martinena/Adobe Stock

For many years, Docker has been the container runtime environment. It’s easy to use and has plenty of third-party tools to make it more efficient and accessible. Of course, Docker isn’t the only option. And if your preferred host operating system is of the Red Hat Enterprise Linux flavor, like RHEL, Rocky Linux, or AlmaLinux, Podman has replaced Docker.

SEE: Hire Kit: Backend Developer (TechRepublic Premium)

The good news is that Podman is similar to Docker, especially when it comes to basic usage. Note that Podman has no equivalent to Docker Swarm, except for Kubernetes and Nomad, which aren’t nearly as easy to deploy and use as Swarm.

You can do many of the same things with Podman as you can with Docker. And I’ll show you that now. We’re taking our first steps with Podman to help you feel more comfortable using this runtime engine.

What you need to get started with Podman

First, you need a Linux distribution that supports Podman. RHEL-based distributions such as Rocky Linux and AlmaLinux ship with Podman installed by default. If you prefer Ubuntu-based distros, you can always install Podman fairly easily. I’m assuming you’re either using a distro that comes with Podman, or have Podman installed on your Ubuntu-based distro of choice.

So let’s get to work.

How to find and drag an image

You remember how to pull an image with Docker, right? Does docker pull nginx:latest ring a bell? It’s the same with Podman. Before we fetch an image, let’s do a search and see what NGINX images are available. To do this, issue the command:

podman search nginx

You should see several entries from Docker Hub and the redhat.io registry. These entries include the latest official NGINX images, which should be listed as docker.io/library/nginx. To get this image, issue the command:

podman pull nginx:latest

This is where one of the first differences between Docker and Podman will appear. If you use Docker to fetch this image, it simply fetches it from docker.io by default. With Podman, you can choose between Registry.access.redhat.com, Registry.redhat.io, or docker.io (Figure A). You must then use the cursor keys to select which registry you want to pull from and accept the selection by pressing Enter on your keyboard.

Figure A

Podman command line interface.
You have a choice of registries to pull the official NGINX image from.

To verify that the image was retrieved, enter the following command:

podman images

You should see your newly retrieved image listed.

Now let’s deploy a container with our newly fetched image.

How to deploy a container with Podman

With Docker, deploying a container from a saved image is as simple as:

docker run –name docker-nginx -p 8080:80 -d nginx

Podman provides a very similar deployment command that looks like this:

podman run --name podman-nginx -p 8080:80 -d nginx

Let’s break this command down:

  • podman is the container runtime engine command.
  • –name gives our container a unique name. If you skip this, Podman will assign a random name.
  • -p tells podman that you will define the port to use.
  • 8080:80 tells Podman to use 8080 as the external port (to the container) and map it to internal port 80.
  • -d runs the container in detached mode, so it returns your bash prompt.
  • nginx is the image to use for the container.

To verify a successful deployment in Docker, issue the following command:

docker ps -a

For Podman, the command is similar:

podman ps -a

You should see that your newly deployed container is up and running.

How to stop and remove containers with Podman

Just like Docker, when you deploy a Podman container, you see a string that serves as the container ID. To stop this container you just need to use the first four characters in this id as in:

podman stop b529

To completely remove the container, the command is:

podman rm b529

If you had just stopped the container and not deleted it, you could restart it like this:

podman restart b529

The above commands are all similar to the Docker environment.

How to access a running container

With Docker, you can access the bash prompt of a currently running container with a command like this:

docker exec -it docker-nginx /bin/bash

The above command would bring you into the bash prompt of the container named docker-nginx. Doing this with Podman is exactly the same and looks like this:

podman exec -it podman-nginx /bin/bash

You should now see something like this:

root@b529f338ed24:/#

You can then leave the container with the exit command.

Here’s how to get started with the Podman Container Runtime Engine. Put simply, if you can use Docker, you can use Podman with very little effort. Next time, let’s create and manage volumes with Podman.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for the latest tech advice for business professionals from Jack Wallen.

Leave a Reply

Your email address will not be published. Required fields are marked *