21.0 How to Podman

Containers are packages of software that contain all of the necessary elements to run in any environment. In this way, containers virtualize the operating system and run anywhere, from a private data center to the public cloud or even on a developer’s personal laptop.

Docker Zero to Hero: https://youtu.be/3c-iBn73dDE

Podman

First we need to install Podman:

dnf install podman -y

Let’s find a httpd image:

podman search httpd

That is a lot of results we want a specific image namely the apache official one. found here: https://hub.docker.com/_/httpd

The one we want is the following:

podman search docker.io/library/httpd

We can get the image by using a docker pull:

podman pull httpd

The pull should look like this:

[root@rhcsa ~]# podman pull httpd
✔ docker.io/library/httpd:latest
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob 31b3f1ad4ce1 done
Copying blob 5bfb2ce98078 done
Copying blob f29089ecfcbf done
Copying blob a9fcd580ef1c done
Copying blob a19138bf3164 done
Copying config f2789344c5 done
Writing manifest to image destination
Storing signatures
f2789344c57324805883b174676365eb807fdb4eccfb9878fbb19054fd0c7b7e

Let’s see if it worked out:

podman image list

Output should be as this:

[root@rhcsa ~]# podman image list
REPOSITORY               TAG         IMAGE ID      CREATED      SIZE
docker.io/library/httpd  latest      f2789344c573  2 weeks ago  150 MB

Great now we have the image downloaded now we need to run it and test it:

podman run -d -it --name httpd -p 8080:80 httpd

flag

Action

run

run the container

-d

run in detached modus

-i

When set to true, keep stdin open even if not attached. The default is false.

-t

when set to true, Podman will allocate a pseudo-tty and attach to the standard input of the container. This can be used, for example, to run a throwaway interactive shell.

–name

sets a name for the run

-p

Open a port from the container to the vm running the container local-port:container-port

httpd

the name of the image

Test the container:

curl localhost:8080
[root@rhcsa ~]# curl localhost:8080
<html><body><h1>It works!</h1></body></html>

Like this!

volume bind

Make a new directory:

mkdir -p /opt/podman/

Create a new index.html file:

vim /opt/podman/index.html

Place some text in there go wild!

Let’s stop the container that is running:

podman ps

This shows you which containers are running.

[root@rhcsa ~]# podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS                 NAMES
37f879f782bf  docker.io/library/httpd:latest  httpd-foreground  6 minutes ago  Up 6 minutes ago  0.0.0.0:8080->80/tcp  httpd

You can stop the container using the name we gave it and we need to remove it:

podman stop httpd
podman rm httpd

Now let’s run a new container with our own website:

podman run -d -it --name httpd -p 8080:80 -v /opt/podman/:/usr/local/apache2/htdocs httpd

Check if it works:

curl localhost:8080

Now let’s check inside the container to see the file:

podman exec -it httpd bash
ls /usr/local/apache2/htdocs
cat /usr/local/apache2/htdocs/index.html

Is it your file?
Quit with exit.

Start Container on boot

We can use podman to create a systemd file so we can boot the container on start-up:

podman generate systemd --new --name httpd >> /etc/systemd/system/container-httpd.service

This has created a systemd file and used >> /etc/systemd/system/container-httpd.service to copy that file to the systemd directory where the services are stored. Now we can start and enable the service like any other service.

Now we can enable the container in systemd:

systemctl enable container-httpd --now

Reboot your VM And check the service and site:

systemctl status container-httpd
curl localhost:8080