Podman Tutorial

  • |
  • 15 December 2021
Post image

In this one-shot tutorial, we are going to learn what Podman is, how to use it, the differences between Docker and Podman and more..

What is Podman?

Podman is a daemonless container engine for developing, managing and running container and container image on our linux system.

Podman also provides a Docker-compatible command line and works well with the Docker. In simply, we can also create an alias alias docker=podman.

One of the best features of podman is run rootless containers. A rootless container is running and managing containers without root privileges.

I don’t want to bother you with the installation steps. Because podman web page has awesome step by step installation processes for various linux distros, mac and more.. Here is the link

Podman version

Use the podman versioncommand:

$ podman version
Version:      3.4.2
API Version:  3.4.2
Go Version:   go1.16.8
OS/Arch:      linux/amd64

Podman System information

We can look up the system information via podman infocommand:

$ podman info
  arch: amd64
  buildahVersion: 1.23.1
  - memory
  - pids

Where podman pull images

At the time of writing this article, podman will look at the following registries to find appropriate image(s):

["registry.fedoraproject.org", "registry.access.redhat.com", "docker.io", "quay.io"]

These registries are defined in the file : /etc/containers/registries.conf

$ less /etc/containers/registries.conf
# # An array of host[:port] registries to try when pulling an unqualified image, in order.
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "docker.io", "quay.io"]

Container Storage

In podman, each user has its own container storage. For instance, if user_a has the image called postgres, then if user_b needs the same image podman will try to pull image from the remote repository instead of using the local image.

Other than root, containers are stored in the directory: $HOME/.local/share/containers/storage/

If you want to learn where my container storage is, you can run the $ podman info command:

$ podman info
  configFile: /home/mehmetozanguven/.config/containers/storage.conf
    number: 11
    paused: 0
    running: 0
    stopped: 11
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/mehmetozanguven/.local/share/containers/storage
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
    number: 17
  runRoot: /run/user/1000/containers
  volumePath: /home/mehmetozanguven/.local/share/containers/storage/volumes

Let’s continue with the example,

Example: Httpd Container

We can pull httpd images from the docker repo:

[mehmetozanguven@fedora ~]$ podman pull docker.io/library/httpd

[mehmetozanguven@fedora ~]$ podman pull docker.io/library/httpd
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob d0c6942edac3 done
Writing manifest to image destination
Storing signatures

We can verify the images by listing all images:

 [mehmetozanguven@fedora ~]$ podman images
 REPOSITORY                     TAG         IMAGE ID      CREATED      SIZE
 docker.io/library/httpd        latest      d54056386fbb  2 days ago   142 MB

To run httpd container

$ podman run -d -p 8080:80 d54056386fbb
  • -d means => runs in detached mode
  • -p 8080:80: Run Container in port 80 AND
    • For all requests in the host with port 8080 redirects to the container port 80

Now go to the http://localhost:8080/, you will see=> It works!

You can also access port 8080 from your mobile phone, tablet etc. But these devices also must connect to the same network (Basically same wifi).

For instance my local host ip address (the one running the podman), if i open the my mobile browser, i will see that: It works!

To see running container:

[mehmetozanguven@fedora ~]$ podman ps -a
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS                 NAMES
bd0ccd219016  docker.io/library/httpd:latest  httpd-foreground  4 minutes ago  Up 4 minutes ago>80/tcp  infallible_shockley

To get container’s pid number:

$ podman top -l
# or
$ podman top -{containerId}

-l is used for latest container

To stop container:

$ podman stop -l
# or
$ podman stop {containerId}

To remove container:

$ podman rm -l
# or
$ podman rm {containerId}

To view container’s log:

$ podman logs -l

That’s the basic instructions for podman, you can find more and more on the Internet. I will continue with the postgresql example.

You May Also Like

Dockerfile Format and Commands

Dockerfile Format and Commands

Before diving into the podman or docker itself, we should first know how to create dockerfile. Because writing a Dockerfile is the first step to …

Quick Intro to Container(s)

Quick Intro to Container(s)

Recently, I decided to learn containers (specifically Podman) to simply run my applications in an isolated environment. I can directly jump into the …