Skip to main content

Create fast, easy, and repeatable containers with Podman and shell scripts

Get started with containers in a fast, repeatable way through the familiar shell scripting interface.
Blue, white, orange, and brown containers stacked

Pexels, CC0

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  latest  054741915cf1  2 days ago   629 MB      latest  bbf6571db497  3 days ago   521 MB      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:


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 \
--volume /var/local/mysql:/var/lib/mysql:Z \

podman run --pod blog --name wordpress -e WORDPRESS_DB_HOST=mysql \

The next one starts a web server:


podman run --name=httpd -p 8081:80 \
--volume /var/local/httpd:/usr/local/apache2/htdocs:Z \

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

$ ls -R /var/local/

httpd  mysql



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

    <title>Enable SysAdmin</title>
    <p>Hello World!</p>

[ 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:

$ ./


$ ./


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
(Alexon Oliveira, CC BY-SA 4.0)

Then the basic WordPress container app:

Basic WordPress container app
(Alexon Oliveira, CC BY-SA 4.0)

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,

Topics:   Podman   Containers  
Author’s photo

Alexon Oliveira

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. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.