Skip to content

Podman - Creating a pod - Part 7

In this part we will create a pod and assign containers to it, we will of course talk a little bit about how it works and what to think about.

Create a pod

If you have been following along in this guide then there should not be any pods yet, to confirm this run podman pod list.

$ podman pod list
POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS

To create a pretty basic pod run the command below, when you get the hang of creating pods you can start exploring all the option and tweaks that you can do with them, more information can be found on podmans site here...

$ podman pod create --publish 8080:80/tcp --name MyWebPod

Now the pod is created and to list it run the following command.

$ podman pod ls
POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
a6644ab3fc91  MyWebPod    Created     36 seconds ago  d6231ace10ea  1

If you look closely you will see that there are already a container attached to this pod, how can this be you might ask, we have not added any containers yet...

Run the following command and look for the tag Containers

$ podman pod inspect MyWebPod

"Containers": [
          "Id": "d6231ace10ea7039a10402925fbe66f717b941be90a05cc087cba0d1d818d53d",
          "Name": "fa24d8aeae92-infra",
          "State": "configured"

Here you see a container called -infra, one of the main purposes of this container is to go to sleep and to hold the namespace of the pod alive, but it also has the purpose of getting all of the pod settings assigned to it, like ports. cgroups and so on.

An important thing to note, you cannot assign new ports and such on an already created pod, so plan ahead before setting up a pod, to change any setting for a pod it must be recreated, thats why we assigned port 8080 on it from the start.

There is a deep dive article over at Red Hat i recommend you read when it's time to deepen your knowledge about what you can configure on a pod.

Assign containers

Time to assign some containers to our pod and this is done either via the podman run or podman create command for the containers you want to assign to a pod.

We will assign a web container and a database container to our pod, one via the run and the other via create.

If you still have our MyWebServer running, go ahead and remove it.

$ podman rm -f MyWebServer

Web container.

$ podman run --pod MyWebServer --name MyWebServer --detach

Database container.

$ podman create --pod MyDbServer --name MyDbServer

As you can see there are some differences, first of all, we added the --pod command and pointed it to our created pod, and secondly, we did not assign any ports to the containers, this is done on pod level and not on container level when using pods.

Now if you run the following command again, you will see that is has 3 containers attached to this pod.

$ podman pod ls
POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
a6644ab3fc91  MyWebPod    Created     38 minutes ago  d6231ace10ea  3

Run the following command and see what it says under STATUS

$ podman pod ps
POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
a6644ab3fc91  MyWebPod    Degraded    38 minutes ago  26e72b398178  3

It says degraded, but why???

Well simply because the database container is not started and we cannot start it either, that is simply because we did not specify any of the following required parameters when creating the container.

--env MARIADB_USER=example-user
--env MARIADB_PASSWORD=my_cool_secret
--env MARIADB_ROOT_PASSWORD=my-secret-pw

Some container require parameters passed into them like passwords or other parameters at first time run or creation, and thats where --env parameter comes into the picture, of course the image must have been built to read these variables that is passed into it, so always check the creators page on the repository where you fetched the image for any information like this.

So remove that container, recreate and run it as below.

$ podman rm -f MyDbServer
$ podman create --pod MyWebPod --name MyDbServer \
--env MARIADB_USER=user \
--env MARIADB_PASSWORD=mypass \
$ podman start MyDbServer

Now list the container again and see what it says under STATUS

$ podman pod ps
POD ID        NAME        STATUS      CREATED            INFRA ID      # OF CONTAINERS
a6644ab3fc91  MyWebPod    Running     About an hour ago  26e72b398178  3

Now it says running and the pod is running perfect, and you saw that we could remove and attach containers to an existing pod.

But can the web container actually talk to the database container???

Well there is only one way to find out.

Start by connecting to the web container with the following command.

podman exec --interactive --tty --user 0 MyWebServer /bin/bash

This will connect to the web container in so called interactive mode and you can manage the container from the inside.

Now run the following command and see what it outputs.

root@MyWebPod:/# curl -v telnet://
*   Trying
* Connected to ( port 3306 (#0)
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failure writing output to destination
* Closing connection 0

Look at line 2 and you will see that it says connected, and this confirms that you can talk from the web container to the database container within the pod.

When done simply type exit and you will exit the interactive mode.

To see which pod containers belong to, you can use the following command, look far to the right and you will se the pod name.

$ podman ps --pod
CONTAINER ID  IMAGE                             COMMAND               CREATED            STATUS                PORTS                 NAMES               POD ID        PODNAME
26e72b398178                                    2 hours ago        Up About an hour ago>80/tcp  a6644ab3fc91-infra  a6644ab3fc91  MyWebPod
4bf4627b6749    nginx -g daemon o...  About an hour ago  Up About an hour ago>80/tcp  MyWebServer         a6644ab3fc91  MyWebPod
97b9b7de0d92  mariadbd              36 minutes ago     Up 35 minutes ago>80/tcp  MyDbServer          a6644ab3fc91  MyWebPod

When it comes to restarting and stopping pods and containers, you can do both, it's just a matter of what you need to restart or stop.

To restart a container you use the podman container restart and you can restart single containers within a pod, on some containers i do a stop and start instead of restart to make sure it has stopped properly.

$ podman container restart MyWebServer

And for a pod you use podman pod restart.

$ podman pod restart MyWebPod

I currently do not use the restart command since on the version of podman i'm running there seems to be an issue where it tries to start containers and pods to fast before everything is stopped properly and i get errors and not all containers are started, but try it, maybe you have a version newer and there it works, have seen reports that version 2.0.27 of the common package and newer is fixed, 22.04 LTS still has version 2.0.25 as of this guide.

So i do a stop and restart instead, where i wait a few second between the commands and this seems to work better.

$ podman pod stop MyWebPod
  wait a couple of seconds...
$ podman pod start MyWebPod


In this part we talked a bit more about pods and got hands on with creating a pod and assigning containers to it, we talked about some things to think about.

In next part we will talk a little about network in regards to podman.