Subscribe to the feed

Podman is a daemon-less container engine for developing, managing, and running Open Container Initiative (OCI)-compliant containers and container images. It follows industry standards to provide a robust container-management tool that you can also integrate into Kubernetes and other services as needed.

Better still, Podman is Docker-compatible to the point that you can simply alias the Docker command-line interface (CLI) to the Podman command (alias docker=podman) and change nothing about your workflow or scripts.

This article starts a series about Podman's features, and I'll reuse the setup below in my future articles. In this one, I'll show you how to get started with containers in a fast and repeatable way through the familiar interface of shell scripting.

Setting things up

Because containers are designed to be disposable or ephemeral, it's important to make your containers repeatable. You want to be able to create a container with the environment you need, destroy it when you no longer need it, and know that you can recreate it later with no added effort. Many users look to the Dockerfile format for this, but a good shell script can be just as useful and has the added benefit of greater flexibility. For example:

$ podman --version

podman version 3.0.2-dev

I have already pulled some container images that I will use to run my containers and pods:

$ podman image ls

REPOSITORY                   TAG     IMAGE ID      CREATED      SIZE
docker.io/library/wordpress  latest  054741915cf1  2 days ago   629 MB
docker.io/library/mysql      latest  bbf6571db497  3 days ago   521 MB
docker.io/library/httpd      latest  ea28e1b82f31  3 days ago   148 MB

Scripting containers

I have created two simple scripts to deploy my pod and containers. The first creates a pod with a WordPress container:

#!/bin/bash
# create_blog.sh

set -e   #exit on most errors

podman pod create --name blog --infra --publish 8080:80 --network bridge 

podman run --pod blog --name mysql -e MYSQL_USER=alexon \
-e MYSQL_PASSWORD=123456 -e MYSQL_DATABASE=wpdb \
-e MYSQL_ROOT_PASSWORD=567890 \
--volume /var/local/mysql:/var/lib/mysql:Z \
-d docker.io/library/mysql 

podman run --pod blog --name wordpress -e WORDPRESS_DB_HOST=mysql \
-e WORDPRESS_DB_USER=alexon \
-e WORDPRESS_DB_PASSWORD=123456 \
-e WORDPRESS_DB_NAME=wpdb \
-d docker.io/library/wordpress

The next one starts a web server:

#!/bin/bash
# create_web.sh

podman run --name=httpd -p 8081:80 \
--volume /var/local/httpd:/usr/local/apache2/htdocs:Z \
-d docker.io/library/httpd

I'm referencing external mount points for my containers. Here are the contents of these directories:

$ ls -R /var/local/

/var/local/:
httpd  mysql

/var/local/httpd:
index.html

/var/local/mysql:

$ cat /var/local/httpd/index.html

<html>
  <header>
    <title>Enable SysAdmin</title>
  </header>
  <body>
    <p>Hello World!</p>
  </body>
</html>

[ You might also be interested in reading How Podman runs on Macs and other container FAQs. ]

Deploying the containers

With the proper configuration in place, I deploy my containers using my scripts:

$ ./create_web.sh

7c4c01d99cccf70a0c42ebdba458afb8be6d1563de3a91c99519213a4d8654af

$ ./create_blog.sh

a061ffe41575ca69ec48a2151220ba9462ed87c3c54d0f35bfa74507b56ff902
5bd37169ce0de342e5b86f7d8ba057b06cddb05b6d73520fca8c5ca69f1fe353
055fc7959f58921ef11119b44b1d250558272b523765e639a5e5c3aa2ad3d2a0

Just to make sure my applications are running correctly inside my recently deployed containers, I access them through a web browser. First, the basic httpd container app:

Basic httpd container app

Then the basic WordPress container app:

Basic WordPress container app

Both are up and running properly. 

Building familiarity into your container workflow

Containers don't have to be strange concepts to a Linux user. Integrated into the operating system, they're powerful tools for the busy sysadmin. In my next article, I'll demonstrate how Podman provides tools to see information about running pods.

Until then, you can learn more about Podman from 10 Podman guides to do more with containers in 2022Top 10 container guides for sysadmins, and of course, Podman.io.


About the author

Alexon has been working as a Senior Technical Account Manager at Red Hat since 2018, working in the Customer Success organization focusing on Infrastructure and Management, Integration and Automation, Cloud Computing, and Storage Solutions. He is a part of the TAM Practices LATAM team based in São Paulo, Brazil, where his job is partnering with, advocating, trust-advising, and supporting customers in their success goals while making use of the complete portfolio. He also contributes to produce and enhance documentation, knowledge-base articles, blog posts, presentations, webinars, and workshops. He is a member of numerous communities in addition to the Sudoers, like Red Hat Academy and Red Hat Accelerators. When he’s not at work, he enjoys spending quality time with his family (wife, daughter, and cat) and participating in several volunteer jobs.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

Browse by channel

automation icon

Automation

The latest on IT automation for tech, teams, and environments

AI icon

Artificial intelligence

Updates on the platforms that free customers to run AI workloads anywhere

open hybrid cloud icon

Open hybrid cloud

Explore how we build a more flexible future with hybrid cloud

security icon

Security

The latest on how we reduce risks across environments and technologies

edge icon

Edge computing

Updates on the platforms that simplify operations at the edge

Infrastructure icon

Infrastructure

The latest on the world’s leading enterprise Linux platform

application development icon

Applications

Inside our solutions to the toughest application challenges

Original series icon

Original shows

Entertaining stories from the makers and leaders in enterprise tech