Share on Social Media

Explore Docker alternatives with Podman containers and Buildah commands. Learn how to use these powerful containerization tools as alternatives to Docker for managing and building containers efficiently. #centlinux #linux #docker

What is Docker?

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first started in 2013 and is developed by Docker, Inc.

Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

Docker Alternatives:

What is Podman Container?

Podman is a daemon-less, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images. Podman provides a command line interface (CLI) familiar to anyone who has used the Docker Container Engine. Most users can simply alias Docker to Podman (alias docker=podman) without any problems. Similar to other common Container Engines (Docker, CRI-O, containerd), Podman relies on an OCI compliant Container Runtime (runc, crun, runv, etc) to interface with the operating system and create the running containers. This makes the running containers created by Podman nearly indistinguishable from those created by any other common container engine.

Recommended Book: Podman for DevOps (PAID LINK) by Alessandro Arrichiello & Gianni Salinetti 
Recommended Online Training: Working with Docker / OCI Containers using Podmanshow?id=oLRJ54lcVEg&bids=1060093

What is Buildah?

Buildah is a command-line tool for building Open Container Initiative-compatible (that means Docker- and Kubernetes-compatible, too) images quickly and easily. It can act as a drop-in replacement for the Docker daemon’s docker build command (i.e., building images with a traditional Dockerfile) but is flexible enough to allow you to build images with whatever tools you prefer to use. Buildah is easy to incorporate into scripts and build pipelines, and best of all, it doesn’t require a running container daemon to build its image.

Environment Specification

We are using a Rocky Linux 9 minimal installed virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Rocky Linux release 9.0 (Blue Onyx)
  • Hostname – podman-01.centlinux.com
  • IP Address – 192.168.116.131/24

Update your Linux OS

Connect with podman-01.centlinux.com as root user by using a ssh client.

Refresh your yum cache by executing following command.

# dnf makecache
Rocky Linux 9 - BaseOS                          1.3 kB/s | 3.6 kB     00:02
Rocky Linux 9 - AppStream                       850  B/s | 3.6 kB     00:04
Rocky Linux 9 - Extras                          1.3 kB/s | 2.9 kB     00:02
Metadata cache created.

You can update your Linux OS by using the dnf command.

# dnf update -y

If the above command updates your Linux Kernel and relevant packages then you should restart your Linux operating system before moving forward in this guide.

# reboot

After reboot, verify the Linux Kernel and operating system versions used in this tutorial.

# cat /etc/rocky-release
Rocky Linux release 9.0 (Blue Onyx)

# uname -r
5.14.0-70.22.1.el9_0.x86_64

Install Podman Container and Buildah Commands

Now, you are ready to install Podman and Buildah (Docker alternatives) software on your Linux machine.

To get information about podman software package, execute following command at Linux Bash prompt.

# dnf info podman
Last metadata expiration check: 0:09:13 ago on Mon 22 Aug 2022 10:44:57 AM CDT.
Available Packages
Name         : podman
Epoch        : 2
Version      : 4.1.1
Release      : 1.el9_0
Architecture : x86_64
Size         : 12 M
Source       : podman-4.1.1-1.el9_0.src.rpm
Repository   : appstream
Summary      : Manage Pods, Containers and Container Images
URL          : https://podman.io/
License      : ASL 2.0 and GPLv3+
Description  : podman (Pod Manager) is a fully featured container engine that is
             : a simple daemonless tool.  podman provides a Docker-CLI
             : comparable command line that eases the transition from other
             : container engines and allows the management of pods, containers
             : and images.  Simply put: alias docker=podman. Most podman
             : commands can be run as a regular user, without requiring
             : additional privileges.
             :
             : podman uses Buildah(1) internally to create container images.
             : Both tools share image (not container) storage, hence each can
             : use or manipulate images (but not containers) created by the
             : other.
             :
             : Manage Pods, Containers and Container Images
             : podman Simple management tool for pods, containers and images

Similarly, you can execute above command for buildah to get information about each software package.

Now install all four software packages on your Rocky Linux 9 server.

# dnf install -y podman buildah

How to use Podman Containers?

After successful installation, check the version of podman command as follows.

# podman version
Client:       Podman Engine
Version:      4.1.1
API Version:  4.1.1
Go Version:   go1.17.12
Built:        Tue Aug  9 11:43:56 2022
OS/Arch:      linux/amd64

For the ease of Docker users, and to motivate them to migrate to this docker alternatives tool. The podman command syntax has exactly same as of docker command.

Execute following command to search the Alpine Linux image at Docker Hub.

# podman search alpine --filter is-official=true
NAME                      DESCRIPTION
docker.io/library/alpine  A minimal Docker image based on Alpine Linux...

Pull Docker image of Alpine Linux by using podman command.

# podman pull docker.io/library/alpine
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob 213ec9aee27d done
Copying config 9c6f072447 done
Writing manifest to image destination
Storing signatures
9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5

List down the locally available Docker images.

# podman images
REPOSITORY                TAG         IMAGE ID      CREATED      SIZE
docker.io/library/alpine  latest      9c6f07244728  12 days ago  5.83 MB

It is showing the Alpine Linux image that you have pulled in previous command.

To get the low-level information about Alpine Linux image, you can use the inspect switch with podman command.

# podman inspect alpine
[
     {
          "Id": "9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5",
          "Digest": "sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad",
          "RepoTags": [
               "docker.io/library/alpine:latest"
          ],
          "RepoDigests": [
               "docker.io/library/alpine@sha256:1304f174557314a7ed9eddb4eab12fed12cb0cd9809e4c28f29af86979a3c870",
               "docker.io/library/alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad"
          ],
          "Parent": "",
          "Comment": "",
          "Created": "2022-08-09T17:19:53.47374331Z",
          "Config": {
               "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
               ],
               "Cmd": [
                    "/bin/sh"
               ]
          },
          "Version": "20.10.12",
          "Author": "",
          "Architecture": "amd64",
          "Os": "linux",
          "Size": 5830724,
          "VirtualSize": 5830724,
          "GraphDriver": {
               "Name": "overlay",
               "Data": {
                    "UpperDir": "/var/lib/containers/storage/overlay/994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7/diff",
                    "WorkDir": "/var/lib/containers/storage/overlay/994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7/work"
               }
          },
          "RootFS": {
               "Type": "layers",
               "Layers": [
                    "sha256:994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7"
               ]
          },
          "Labels": null,
          "Annotations": {},
          "ManifestType": "application/vnd.docker.distribution.manifest.v2+json",
          "User": "",
          "History": [
               {
                    "created": "2022-08-09T17:19:53.274069586Z",
                    "created_by": "/bin/sh -c #(nop) ADD file:2a949686d9886ac7c10582a6c29116fd29d3077d02755e87e111870d63607725 in / "
               },
               {
                    "created": "2022-08-09T17:19:53.47374331Z",
                    "created_by": "/bin/sh -c #(nop)  CMD ["/bin/sh"]",
                    "empty_layer": true
               }
          ],
          "NamesHistory": [
               "docker.io/library/alpine:latest"
          ]
     }
]

Create and run a Docker container from Alpine Linux image. This command also starts a /bin/sh shell, so you can execute Linux commands thereon.

# podman run -it --rm alpine /bin/sh
/ # uname -r
5.14.0-70.22.1.el9_0.x86_64
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.2
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
/ # exit

To start a podman container in Detached mode, you can use the following variation of same podman command.

# podman run -d alpine
c0e4b9cb8180f45196e11e56ac16c84104cae91e76ffe49d124129b819f73d6f

Get the list of podman containers as follows.

# podman ps -a
CONTAINER ID  IMAGE                            COMMAND     CREATED         STATUS                     PORTS       NAMES
c0e4b9cb8180  docker.io/library/alpine:latest  /bin/sh     28 seconds ago  Exited (0) 29 seconds ago              strange_chebyshev

If you want to remove a podman container, you can do it with the following command.

# podman container rm c0e4b9cb8180
c0e4b9cb8180f45196e11e56ac16c84104cae91e76ffe49d124129b819f73d6f

You can also remove a locally available Docker image as follows.

# podman rmi docker.io/library/alpine
Untagged: docker.io/library/alpine:latest
Deleted: 9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5

How to Use Buildah Command?

Execute following at Linux bash prompt to check the version of buildah command.

# buildah version
Version:         1.26.2
Go Version:      go1.17.12
Image Spec:      1.0.2-dev
Runtime Spec:    1.0.2-dev
CNI Spec:        1.0.0
libcni Version:  v1.1.0
image Version:   5.21.1
Git Commit:
Built:           Tue Aug  9 11:43:07 2022
OS/Arch:         linux/amd64
BuildPlatform:   linux/amd64

Search for the Official Rocky Linux image at Docker Hub.

# podman search rockylinux --filter is-official=true
NAME                          DESCRIPTION
docker.io/library/rockylinux  The official build of Rocky Linux.

Build a Docker container from Rocky Linux image by using buildah command.

# buildah from rockylinux:8
Resolved "rockylinux" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/rockylinux:8...
Getting image source signatures
Copying blob 0049b869cecb done
Copying config 8cf70153e0 done
Writing manifest to image destination
Storing signatures
rockylinux-working-container

Now install Apache HTTP Server on your podman container.

# buildah run rockylinux-working-container dnf install httpd -y

Create a default homepage and copy it at the document root of your Apache HTTP Server.

# echo "Greetings from CentLinux" > index.html
# buildah copy centos-working-container index.html /var/www/html/index.html
ab5f4a82337ede6812db76bcc14eb7f6be9eabf5b6bae36b58d8a9d11da469c5

Define an entrypoint command to start Apache HTTP server. This command will be executed when you run this Docker container.

# buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" rockylinux-working-container

Create a Docker image of your customized podman container.

# buildah commit rockylinux-working-container centlinux-website
Getting image source signatures
Copying blob 879054335f94 skipped: already exists
Copying blob 97462add2843 done
Copying config b1315d0fb9 done
Writing manifest to image destination
Storing signatures
b1315d0fb9813a6b4611e28358f3f361ca1b6bd3fc6479c74be636e538173b01

Get the List of locally available images.

# podman images
REPOSITORY                    TAG         IMAGE ID      CREATED             SIZE
localhost/centlinux-website   latest      b1315d0fb981  About a minute ago  255 MB
docker.io/library/rockylinux  8           8cf70153e062  6 weeks ago         202 MB

Use Buildah with Dockerfile

In the previous section, you have created a Docker image by using buildah ad hoc commands.

Now, you will see how to create a Docker image by buildah command with Dockerfile.

Create a Dockerfile by using vim text editor.

# vi Dockerfile

Add following directives in this file.

# RockyLinux Base
FROM rockylinux:8
# Install httpd
RUN echo "Installing httpd"; dnf -y install httpd
# Expose the default httpd port 80
EXPOSE 80
# Run httpd
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]

The above directives are self explanatory and well commented.

Now, execute buildah command along with bud (Build using Dockerfile) parameter to create your Docker image as described in the Dockerfile.

# buildah bud -t httpd-server
STEP 1/4: FROM rockylinux:8
STEP 2/4: RUN echo "Installing httpd"; dnf -y install httpd
Installing httpd
Rocky Linux 8 - AppStream                       576 kB/s | 9.6 MB     00:17
Rocky Linux 8 - BaseOS                          606 kB/s | 6.6 MB     00:11
Rocky Linux 8 - Extras                          3.3 kB/s |  11 kB     00:03
Dependencies resolved.
================================================================================
 Package         Arch   Version                                 Repo       Size
================================================================================
Installing:
 httpd           x86_64 2.4.37-47.module+el8.6.0+985+b8ff6398.2 appstream 1.4 M
Installing dependencies:
 apr             x86_64 1.6.3-12.el8                            appstream 128 k
 apr-util        x86_64 1.6.1-6.el8.1                           appstream 104 k
 brotli          x86_64 1.0.6-3.el8                             baseos    322 k
 httpd-filesystem
                 noarch 2.4.37-47.module+el8.6.0+985+b8ff6398.2 appstream  40 k
 httpd-tools     x86_64 2.4.37-47.module+el8.6.0+985+b8ff6398.2 appstream 107 k
 mailcap         noarch 2.1.48-3.el8                            baseos     38 k
 mod_http2       x86_64 1.15.7-5.module+el8.6.0+823+f143cee1    appstream 153 k
 rocky-logos-httpd
                 noarch 86.2-1.el8                              baseos     24 k
Installing weak dependencies:
 apr-util-bdb    x86_64 1.6.1-6.el8.1                           appstream  23 k
 apr-util-openssl
                 x86_64 1.6.1-6.el8.1                           appstream  26 k
Enabling module streams:
 httpd                  2.4

Transaction Summary
================================================================================
Install  11 Packages

Total download size: 2.4 M
Installed size: 6.9 M
Downloading Packages:
(1/11): apr-util-bdb-1.6.1-6.el8.1.x86_64.rpm    15 kB/s |  23 kB     00:01
(2/11): apr-util-openssl-1.6.1-6.el8.1.x86_64.r  90 kB/s |  26 kB     00:00
(3/11): apr-1.6.3-12.el8.x86_64.rpm              63 kB/s | 128 kB     00:02
(4/11): apr-util-1.6.1-6.el8.1.x86_64.rpm        51 kB/s | 104 kB     00:02
(5/11): httpd-filesystem-2.4.37-47.module+el8.6 139 kB/s |  40 kB     00:00
(6/11): httpd-tools-2.4.37-47.module+el8.6.0+98 194 kB/s | 107 kB     00:00
(7/11): mod_http2-1.15.7-5.module+el8.6.0+823+f 187 kB/s | 153 kB     00:00
(8/11): mailcap-2.1.48-3.el8.noarch.rpm          27 kB/s |  38 kB     00:01
(9/11): rocky-logos-httpd-86.2-1.el8.noarch.rpm  70 kB/s |  24 kB     00:00
(10/11): brotli-1.0.6-3.el8.x86_64.rpm          139 kB/s | 322 kB     00:02
(11/11): httpd-2.4.37-47.module+el8.6.0+985+b8f 346 kB/s | 1.4 MB     00:04
--------------------------------------------------------------------------------
Total                                           280 kB/s | 2.4 MB     00:08
Rocky Linux 8 - AppStream                       1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x6D745A60:
 Userid     : "Release Engineering <infrastructure@rockylinux.org>"
 Fingerprint: 7051 C470 A929 F454 CEBE 37B7 15AF 5DAC 6D74 5A60
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : apr-1.6.3-12.el8.x86_64                               1/11
  Running scriptlet: apr-1.6.3-12.el8.x86_64                               1/11
  Installing       : apr-util-bdb-1.6.1-6.el8.1.x86_64                     2/11
  Installing       : apr-util-openssl-1.6.1-6.el8.1.x86_64                 3/11
  Installing       : apr-util-1.6.1-6.el8.1.x86_64                         4/11
  Running scriptlet: apr-util-1.6.1-6.el8.1.x86_64                         4/11
  Installing       : httpd-tools-2.4.37-47.module+el8.6.0+985+b8ff6398.    5/11
  Installing       : rocky-logos-httpd-86.2-1.el8.noarch                   6/11
  Installing       : mailcap-2.1.48-3.el8.noarch                           7/11
  Installing       : brotli-1.0.6-3.el8.x86_64                             8/11
  Running scriptlet: httpd-filesystem-2.4.37-47.module+el8.6.0+985+b8ff    9/11
  Installing       : httpd-filesystem-2.4.37-47.module+el8.6.0+985+b8ff    9/11
  Installing       : mod_http2-1.15.7-5.module+el8.6.0+823+f143cee1.x86   10/11
  Installing       : httpd-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_   11/11
  Running scriptlet: httpd-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_   11/11
  Verifying        : apr-1.6.3-12.el8.x86_64                               1/11
  Verifying        : apr-util-1.6.1-6.el8.1.x86_64                         2/11
  Verifying        : apr-util-bdb-1.6.1-6.el8.1.x86_64                     3/11
  Verifying        : apr-util-openssl-1.6.1-6.el8.1.x86_64                 4/11
  Verifying        : httpd-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_    5/11
  Verifying        : httpd-filesystem-2.4.37-47.module+el8.6.0+985+b8ff    6/11
  Verifying        : httpd-tools-2.4.37-47.module+el8.6.0+985+b8ff6398.    7/11
  Verifying        : mod_http2-1.15.7-5.module+el8.6.0+823+f143cee1.x86    8/11
  Verifying        : brotli-1.0.6-3.el8.x86_64                             9/11
  Verifying        : mailcap-2.1.48-3.el8.noarch                          10/11
  Verifying        : rocky-logos-httpd-86.2-1.el8.noarch                  11/11

Installed:
  apr-1.6.3-12.el8.x86_64
  apr-util-1.6.1-6.el8.1.x86_64
  apr-util-bdb-1.6.1-6.el8.1.x86_64
  apr-util-openssl-1.6.1-6.el8.1.x86_64
  brotli-1.0.6-3.el8.x86_64
  httpd-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_64
  httpd-filesystem-2.4.37-47.module+el8.6.0+985+b8ff6398.2.noarch
  httpd-tools-2.4.37-47.module+el8.6.0+985+b8ff6398.2.x86_64
  mailcap-2.1.48-3.el8.noarch
  mod_http2-1.15.7-5.module+el8.6.0+823+f143cee1.x86_64
  rocky-logos-httpd-86.2-1.el8.noarch

Complete!
STEP 3/4: EXPOSE 80
STEP 4/4: CMD ["/usr/sbin/httpd", "-DFOREGROUND"]
COMMIT httpd-server
Getting image source signatures
Copying blob 879054335f94 skipped: already exists
Copying blob fc55e02d4d48 done
Copying config 64b3c1a33f done
Writing manifest to image destination
Storing signatures
--> 64b3c1a33f7
Successfully tagged localhost/httpd-server:latest
64b3c1a33f7aa689d0a704536469f96960917d2b4fd440397a0780324821542c

You Docker image has been created.

List the locally available Docker images to verify it.

# buildah images
REPOSITORY                     TAG      IMAGE ID       CREATED          SIZE
localhost/httpd-server         latest   64b3c1a33f7a   38 seconds ago   255 MB
localhost/centlinux-website    latest   b1315d0fb981   8 minutes ago    255 MB
docker.io/library/rockylinux   8        8cf70153e062   6 weeks ago      202 MB

Final Thoughts

Discover the versatility of Podman and Buildah commands as Docker alternatives for container management and building. With these powerful tools, you can streamline your container workflow and enjoy flexibility beyond Docker’s limitations. If you need assistance in mastering Docker, or any other aspect of containerization, feel free to explore my services on Fiverr here. Happy containerizing!

Leave a Reply

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