Podman on Ubuntu: Building and Running Containers with Dockerfile (Beginner to Practical Guide)

目次

1. Introduction

The Evolution of Container Technology and Why It Matters

In recent years, the importance of container technology has rapidly increased in application development and operations. In particular, the ability to ensure reproducibility by aligning development and production environments has gained strong support among engineers.

Docker has long been the dominant solution in this space, but in recent years, Podman has emerged as a powerful alternative. Podman offers an almost identical CLI (Command Line Interface) to Docker while providing key advantages such as a daemonless architecture, lightweight operation, and rootless execution without requiring root privileges.

Why “Podman + Dockerfile + Ubuntu”?

This article explains modern container operations on Linux by combining three essential elements: Podman, Dockerfile, and Ubuntu.

  • Ubuntu is a widely used Linux distribution suitable for beginners and advanced users alike,
  • Dockerfile serves as a blueprint for building container images,
  • And Podman is a next-generation tool that enables more flexible and secure container management.

With increasing security awareness, using Podman with Dockerfile on Ubuntu has become a popular choice for both individual developers and enterprise environments.

Purpose and Target Audience

The goal of this article is to carefully explain how to build Dockerfiles and create practical containers using Podman on Ubuntu.

This article is intended for readers such as:

  • Those with Docker experience who are interested in Podman
  • Ubuntu users who want to manage containers securely
  • Engineers planning to adopt container technology in their work
  • Beginners who want to try writing Dockerfiles and building images with Podman

In addition to basic usage, this article also covers troubleshooting tips, key differences from Docker, and migration strategies.

2. What Is Podman?

Basic Overview of Podman

Podman (Pod Manager) is a next-generation container management tool developed by the Red Hat–led community. Like Docker, it can build, run, and manage OCI (Open Container Initiative)–compliant containers, but its design philosophy and architecture differ significantly.

The most notable feature is that Podman does not require a daemon. This enables lightweight and secure operation. Podman also supports rootless mode, allowing regular users to manage containers without privilege escalation. Its CLI compatibility with Docker is very high, making migration straightforward.

Key Features of Podman

Below are some of Podman’s main features:

Daemonless Architecture

Podman does not rely on a background daemon process to manage containers. This allows for more efficient resource usage without unnecessary background services.

Rootless (Unprivileged User) Support

Podman allows non-administrator users to start and manage containers. This greatly improves security in multi-user or server environments and significantly reduces security risks.

Docker-Compatible CLI

Podman uses nearly the same command structure as Docker. For example, the following Docker commands work almost identically in Podman:

podman build -t myimage .
podman run -it myimage bash

As a result, Docker users can migrate with minimal friction.

Pod Functionality

Podman incorporates the Kubernetes “Pod” concept, allowing multiple containers to be managed as a single logical unit. This makes Podman highly compatible with Kubernetes and enables smooth transitions from local development to cloud environments.

Compatibility with Ubuntu

While Podman is widely adopted in Fedora and RHEL-based distributions, it also runs stably on Ubuntu. It can be installed from official repositories with relatively simple configuration. Since Ubuntu 20.04 LTS, package support has improved significantly, lowering the barrier to entry.

3. Installing Podman on Ubuntu

Before You Begin: Prerequisites

Before installing Podman on Ubuntu, first check your Ubuntu version. Podman is officially recommended for Ubuntu 20.04 LTS or later. On older versions, required packages may not be available in the official repositories.

You can check your Ubuntu version using the following command:

lsb_release -a

Installing Podman requires sudo privileges. Even if you plan to use Podman in rootless mode, administrator privileges are still required during installation.

Installing Podman from the Ubuntu Official Repository

On recent Ubuntu versions such as 20.04 or 22.04, Podman can be installed easily using APT.

sudo apt update
sudo apt install -y podman

After installation, verify that Podman was installed correctly by checking the version:

podman --version

Installing the Latest Version Using the Official PPA

The Podman version included in Ubuntu’s default repository is often slightly outdated. If you want to use the latest features, you can install Podman from the official PPA.

. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -
sudo apt update
sudo apt install -y podman

This method allows you to use the latest Podman versions equivalent to those on Red Hat and Fedora systems.

Basic Podman Functionality Test

After installation, perform a simple test to confirm that Podman works correctly:

podman info

This command displays Podman’s configuration, version, and supported features such as rootless mode.

You can also test container execution by running an official Alpine Linux image:

podman run --rm -it alpine sh

If the shell starts successfully, Podman is functioning correctly.

4. Dockerfile Basics and Usage with Podman

What Is a Dockerfile?

A Dockerfile is a blueprint used to build container images. It is a text file that defines instructions such as the base image to use, which packages to install, and which files to copy.

Based on this file, container tools like Podman and Docker can automatically build a consistent environment.

Common Dockerfile instructions include:

FROM ubuntu:22.04
RUN apt update && apt install -y curl
COPY ./app.sh /usr/local/bin/app.sh
CMD ["bash", "/usr/local/bin/app.sh"]

This example installs packages on an Ubuntu base image, copies a script, and defines the default execution command.

Using Dockerfile with Podman

Podman can build container images from Dockerfiles in the same way as Docker.

1. Preparing the Project Directory

Create the following directory structure:

project/
├── Dockerfile
└── app.sh

The app.sh file can contain a simple script:

#!/bin/bash
echo "Hello from Podman container!"

Make the script executable:

chmod +x app.sh

2. Building the Image with Podman

Run the following command in the directory containing the Dockerfile:

podman build -t mypodmanapp .

This creates a container image named mypodmanapp.

3. Verifying the Built Image

You can list available images with:

podman images

4. Running the Container

Start a container using the built image:

podman run --rm mypodmanapp

If configured correctly, the output Hello from Podman container! will be displayed.

Dockerfile vs Containerfile

In Podman, files using Dockerfile syntax may also be called Containerfile. This naming reflects a desire for Docker-independent terminology.

There is no functional difference between Dockerfile and Containerfile. Both are fully supported by Podman.

podman build -f Containerfile -t myimage .

You can specify the file name explicitly using the -f option.

5. Practical Example: Creating an Ubuntu-Based Container

Creating a Dockerfile Based on Ubuntu

From here, we will walk through a practical, step-by-step example of creating a Dockerfile based on Ubuntu and building and running a container image using Podman.

First, create the following simple Dockerfile:

FROM ubuntu:22.04

RUN apt update && \
    apt install -y curl && \
    apt clean

COPY hello.sh /usr/local/bin/hello.sh
RUN chmod +x /usr/local/bin/hello.sh

CMD ["/usr/local/bin/hello.sh"]

This Dockerfile performs the following actions:

  • Uses the official Ubuntu 22.04 image as the base
  • Installs the curl package
  • Copies hello.sh from the host into the container
  • Sets hello.sh as the default execution script

Next, create a simple shell script named hello.sh:

#!/bin/bash
echo "Hello, this output is from a Podman container!"

Grant execute permissions to the script:

chmod +x hello.sh

Building the Image with Podman

Once the files are ready, build the image using the following command:

podman build -t ubuntu-hello .

The -t ubuntu-hello option assigns a tag name to the image, and the trailing . specifies the directory containing the Dockerfile.

If the build completes successfully, the image will be stored locally.

podman images

You can use this command to verify that the image was created.

Running and Verifying the Built Image

Run a container from the newly built image using the following command:

podman run --rm ubuntu-hello

Example output:

Hello, this output is from a Podman container!

The --rm option automatically removes the container after execution, making it ideal for testing purposes.

Optional: Running an Interactive Container

If you want to interact with the container directly, you can start it with the -it option and launch Bash:

podman run -it ubuntu-hello bash

This allows you to use the container as a lightweight Ubuntu-based development environment.

6. Useful Podman Features and Tips

Podman’s Strengths: Flexibility and Security

While maintaining Docker compatibility, Podman offers features that enable more flexible and secure container operations. This section introduces practical features and tips that are especially useful in day-to-day workflows.

Secure Operation with Rootless Mode

One of Podman’s most powerful features is rootless mode, which allows regular users to start, stop, and manage containers without administrator privileges.

You can run containers without sudo as shown below:

podman run -it ubuntu bash

Because this operation is confined to the user’s home directory, system-wide impact is minimized. Rootless mode is particularly useful in shared servers and development environments.

Automatic Startup with systemd Integration

Podman supports native integration with systemd, allowing containers to run automatically as Linux services.

You can generate a systemd service unit for a container using the following command:

podman generate systemd --name mycontainer --files --restart-policy=always

This command creates unit files under ~/.config/systemd/user/. After generation, enable and start the service as follows:

systemctl --user daemon-reexec
systemctl --user enable --now container-mycontainer.service

This configuration ensures that containers automatically start when the system boots.

Managing Multiple Containers with podman-compose

In addition to managing single containers, Podman supports multi-container orchestration. By using podman-compose, you can achieve functionality similar to Docker Compose.

Install podman-compose using pip:

pip install podman-compose

Because it is largely compatible with docker-compose.yml files, you can often reuse existing configurations.

Starting services is as simple as running:

podman-compose up -d

This allows you to reproduce complete development environments instantly even when using Podman.

Additional Useful Commands and Tips

Cleaning Up Unused Images and Containers

podman system prune -a

This command removes unused containers, images, and temporary files, helping keep your storage clean.

Enabling Command Completion (bash/zsh)

You can install command completion support with the following package:

sudo apt install podman-docker

This enables Docker-like command completion for Podman, improving productivity.

7. Migration Guide: From Docker to Podman

Why Migration to Podman Is Gaining Attention

Docker has long been synonymous with container technology, but in recent years, a shift toward Podman as a more lightweight and secure alternative has gained momentum. In particular, Red Hat Enterprise Linux (RHEL) and Fedora have reduced Docker support and adopted Podman as the default container engine, prompting many organizations to consider migration.

This section explains practical steps and important considerations for migrating smoothly from Docker to Podman.

Command Compatibility Between Docker and Podman

Podman maintains a high level of CLI compatibility with Docker, allowing most commands to be directly replaced without modification.

DockerPodman
docker build -t myapp .podman build -t myapp .
docker run -it myapppodman run -it myapp
docker imagespodman images
docker pspodman ps

This makes it possible to switch to Podman without changing your workflow, which is one of its biggest advantages.

Achieving Full Compatibility with podman-docker

If existing scripts, CI/CD pipelines, or tools assume the presence of the docker command, you can install the podman-docker package to make Podman act as a drop-in replacement.

sudo apt install podman-docker

After installation, the docker command becomes a symbolic link to Podman:

which docker
# → /usr/bin/docker → symbolic link to podman

This allows existing Docker-based scripts to run on Podman without modification.

Replacing docker-compose with podman-compose

For projects that use Docker Compose to define multi-container environments, podman-compose provides a compatible alternative.

While compatibility is generally high, note the following limitations:

  • Some Compose options (such as depends_on) may be unsupported or behave differently
  • Differences may exist in event logging and health check behavior

For typical configurations such as a web server and database combination, migration is usually straightforward.

Migrating Images and Volumes

Docker images stored locally cannot be accessed directly by Podman. You must either re-pull them or export and import them.

Option 1: Re-pull Images with Podman

podman pull ubuntu:22.04

Option 2: Export from Docker and Import into Podman

# Export from Docker
docker save myimage > myimage.tar

# Import into Podman
podman load < myimage.tar

This enables Docker-built images to be reused in Podman.

Additional Migration Considerations

  • Rootless operation differences: Docker typically assumes root usage, while Podman is designed for rootless operation
  • Daemon architecture: Podman is daemonless, changing how background processes are managed
  • Log and data storage locations differ and should be reviewed during migration

8. Frequently Asked Questions (FAQ)

Q1. What is the main difference between Podman and Docker?

A1. The most significant difference is that Podman operates without a daemon. This allows for lighter and more secure operation. Podman also supports rootless mode, enabling container management without privilege escalation. CLI compatibility with Docker is very high.

Q2. What is the difference between Dockerfile and Containerfile?

A2. There is no functional difference at all. Both files describe container build instructions using identical syntax.
The name Containerfile is preferred in OCI-compliant projects to avoid Docker-specific terminology. In practice, Dockerfile works perfectly with Podman.

Q3. Can Docker Compose be used with Podman?

A3. Docker Compose is not supported directly, but you can use podman-compose as an alternative. It interprets docker-compose.yml files in a Podman environment.

Some options such as depends_on are limited, so testing is recommended for complex setups.

Q4. Does Podman run stably on Ubuntu?

A4. Yes. Podman runs stably on Ubuntu 20.04 LTS and later. It is available in the official Ubuntu repositories and can be installed easily using apt. For newer versions, using a PPA is also an option.

Q5. Are there limitations when using rootless mode?

A5. Rootless mode restricts certain privileged operations and binding to ports below 1024. However, these limitations can often be bypassed using port forwarding. For most use cases, rootless mode is fully practical.

Q6. Can Podman pull the same images as Docker Hub?

A6. Yes. Podman can pull images from Docker Hub by default. In some environments, you may need to explicitly specify the registry and namespace:

podman pull docker.io/library/ubuntu

Podman also supports other registries such as Quay.io and GitHub Container Registry.

Q7. Is Podman suitable for production environments?

A7. Yes. Podman includes features required for production use, such as Kubernetes-compatible pod concepts and systemd integration. In security-sensitive environments, Podman may be a better choice than Docker.

Podman is already the default container engine in RHEL and Fedora and has extensive production adoption.

年収訴求