How to deploy a pod with Podman

Learn how to get more flexibility and efficiency out of Podman by using pods to control your containers.

How to deploy a pod with Podman Learn how to get more flexibility and efficiency out of Podman by using pods to control your containers.

Podman is the new container deployment engine for CentOS 8 and RHEL 8. Although it has the same goal as the Docker engine (deploying and managing containers), it does so in a very different way--at least under the hood. From the user perspective, it's quite similar to Docker in how it works. 

For the most part.

Yes, you pull images and deploy containers in the same fashion as you do with the Docker engine. But, Podman has a couple of new tricks up its sleeve. One such trick is pods. Pods are a group of one or more containers that operate together. Think of pods as a way to group related containers together for easier management (such as a Wordpress container and its required MySQL database container managed from a single pod). Because Podman deploys each container as its own process, this can be a very efficient and easy way of creating interconnected containers.

I want to walk you through the process of deploying a pod with Podman on CentOS 8.

SEE: Hiring kit: Database administrator (TechRepublic Premium)

What you'll need

The only things you'll need to deploy your first Podman pod are:

  • A running instance of CentOS 8 with Podman installed

  • A user with sudo privileges

To find out how to install Podman on CentOS 8, see: How to install the Podman container engine on CentOS 8.

How to create a new pod

The first thing to be done is the creation of a new pod. The command to create a new pod is:

podman pod create

You'll know if the pod was successfully created when the command returns an ID for the new pod (Figure A).

Figure A

podmana-2.jpg

Our new pod has been created.

That will create a very basic pod. You can create a pod using a number of options, such as:

  • --cgroup-parent value - Set the parent cgroup for the pod

  • --infra - Create an infra container associated with the pod that will share namespaces

  • --infra-command value - A command that will be run on the infra container when the pod is started (such as "/pause")

  • --infra-image value - The infra container image to be associated with the pod

  • --label value - Set metadata for a pod

  • --label-file value - Set the metadata for a pod from a line-delimited file of labels

  • --name value - Assign a name to the new pod

  • --pod-id-file value - Write the pod ID to a file

  • --publish value - Publish a container's port (or a range of ports) to the host

  • --share value - A comma-delimited list of kernel namespaces to be shared with

List the newly created pod with the command:

podman pod list

The listing of the pod (Figure B) will contain the random name created for the pod. You'll need that name in order to add a container to this pod.

Figure B

podmanb-2.jpg

Our new pod listing.

You will also notice the new pod contains a single infra container. This new container was randomly created for the pod. You can list that container with the command:

podman ps -a --pod

The output of that command will list any containers that have been deployed without sudo privileges (so it will include the random container within our new pod).

How to add a container to the pod

Next, we'll add a container to the newly deployed pod. Note: You'll need that randomly assigned name (or the name you gave the pod using the --name option). In my example, the pod name is silly_bhabha. Let's use the official Ubuntu image to deploy a container to the new pod. This container will run the top command, though we won't see the output of that command. 

To deploy that container to the pod, the command would be:

podman run -dt --pod silly_bhabha ubuntu top

We should now see our pod has more than one container, using the command:

podman pod ps

In the listing (Figure C), you'll see the number of containers is three.

Figure C

podmanpodc-2.jpg

The silly_bhabha pod now has three containers.

To view the individual containers, issue the command:

podman ps -a --pod

In the detail listing, you'll see the command that each container is running (Figure D).

Figure D

podmanpodd-2.jpg

The details for individual containers.

It is also possible to create a new pod and deploy a container to it with a single command. Say you want to deploy an nginx container, exposing external port 3100 to internal port 80, to a new pod named trtest. That command would be:

podman run -dt --pod new:trtest -p 31000:80 nginx

The output will list the newly created container ID. You can add more containers to this pod in the same fashion as we did earlier. Check to make sure the newly created pod is ready with the command:

podman pod list

As you can see (Figure E), our new trtest pod has been created and includes more than just the random container.

Figure E

podmanpode-2.jpg

Our new trtest pod is ready.

To stop a pod and all associated containers, you must first find it's ID. To do that, issue the command:

podman ps -p

The ID will be listed under the POD column (Figure F).'

Figure F

podmanpodf-2.jpg

The ID of our pod.

Stop the pod with the command:

podman stop ID

Where ID is the first four characters of the pod ID.

To restart a pod and all associated containers, issue the command:

podman start ID

Where ID is the first four characters of the pod ID.

And that's the gist of deploying a pod with podman. There is, of course, much more to be learned about managing pods with Podman, but this will get you started.

Also see

container.jpg