// LEARN LINUX TV • ARTICLE

Podman Tutorial for Beginners: Linux Containers Made Easy

ADVERTISEMENT

Learn how to use Podman on Linux in this beginner-friendly, hands-on tutorial! We’ll compare Podman vs Docker, install Podman, run your first container, launch an Ubuntu container with an interactive shell, and deploy an NGINX web server with port mapping.

You’ll also learn essential Podman commands for managing container images, stopping containers, and cleaning up unused resources. Whether you’re new to Linux containers or exploring Docker alternatives, this tutorial will help you get started with Podman.

YouTube player
Support Learn Linux TV and grab my "Linux Troubleshooting Strategies" ebook - filled with expert advice for complicated SysAdmin situations.

Why Podman?

And the first thing I want to do is come back to a question I asked earlier: Why is Podman necessary? Wouldn’t it be better to just use Docker, since that’s what everyone else uses? What makes Podman different?

Well, as I mentioned earlier, Podman is an alternative to Docker, and it can even run the same container images. But one of the biggest differences is how it manages those containers, which actually has some interesting security benefits.

With a typical Docker installation, the Docker daemon runs with root privileges. And while that doesn’t necessarily mean every process inside a container runs as root on the host, it does mean that Docker’s management service has elevated privileges.

Now, Docker does support what’s called rootless mode, which allows you to run its daemon and containers without root privileges. But that’s something you generally have to configure separately.

Podman, on the other hand, was designed with rootless containers in mind. You can run containers as your regular Linux user, without needing a privileged daemon to manage them.

And that’s an important distinction, because it can reduce the potential impact of a security vulnerability.

Another major difference is that Podman uses what’s called a daemonless architecture.

With Docker, there’s a background service called the Docker daemon that’s responsible for managing containers. In a typical installation, this service remains running even when you’re not actively working with Docker.

Podman takes a different approach.

Rather than relying on a central daemon, Podman launches containers directly, using a separate process to monitor each container.

For example, if I log into my Linux server and launch a container with Podman, there’s no central Podman service that needs to be running in the background. Podman starts the container, and once it’s running, the Podman command itself can exit. The container continues running independently.

And when I stop that container, its associated processes can shut down without leaving a central Podman daemon running.

This approach can reduce the attack surface of the container management system, since there’s no continuously running, privileged management daemon required.

Another benefit is Podman’s integration with systemd, which is the service manager used by most modern Linux distributions.

Podman supports something called Quadlet, which allows you to define containers using configuration files that systemd can turn into services.

That means you can manage your containers using familiar commands like systemctl, configure them to start automatically, and integrate them with the rest of your Linux system.

For Linux administrators, that’s a pretty compelling feature.

Now, even though Podman has some interesting advantages, that doesn’t mean there aren’t tradeoffs.

For example, you might occasionally encounter an application or deployment that works perfectly with Docker but requires some adjustments to work with Podman.

Docker is extremely popular, and because of that, many applications and deployment instructions are tested primarily against Docker. Podman is largely compatible, but there can be differences, especially when applications depend on Docker-specific behavior.

Docker Compose is another example.

While Podman can work with Compose-based workflows, Docker generally provides a more straightforward experience because Compose was designed around the Docker ecosystem.

And of course, there are other advantages and disadvantages to both tools that we won’t have time to cover here.

But to summarize, Podman is a compelling option if you value rootless containers, a daemonless architecture, and tight integration with systemd.

Docker, on the other hand, might be a better fit when you’re working with applications or tooling that specifically depend on its ecosystem.

Neither option is automatically the best choice for every situation. Ultimately, it comes down to the workload you’re trying to run.

So, now that we understand some of the benefits of Podman, let’s take a look at how to actually use it!

Installing & Using Podman

To get started with Podman, the first thing we’ll need to do is install it.

Thankfully, Podman is available in the repositories of most major Linux distributions, so installation is usually pretty straightforward.

For example, on my local system, which runs Debian, I can install it using apt, just like any other package:

sudo apt install podman

But anyway, now that we have Podman installed, let’s make sure everything works by running our first container.

And for that, we’ll use the classic Hello World example:

podman run --rm docker.io/library/hello-world

This command tells Podman to run a container using the Hello World image.

We’re also including the --rm option, which tells Podman to automatically remove the container once it finishes running. Since this is just a quick test, there’s really no reason to keep it around afterward.

Now, for those of you who are completely new to containers, there’s an important distinction I want to explain here.

Containers are created from something called images. You can think of an image as a template containing an application and the files and dependencies it needs to run.

When you launch a container, Podman uses that image to create an instance of it.

In this example, we’re using the Hello World image from Docker Hub, which is a popular online registry for container images.

And something else worth mentioning is that we didn’t actually have to download the image separately.

When you run a container using an image that isn’t already available locally, Podman will automatically download it for you.

Another thing I’d like to point out is how similar this command looks to Docker.

In fact, if we had Docker installed instead of Podman, we could replace podman with docker, and the command would work essentially the same way.

The command syntax is so similar that if you already have a Docker cheat sheet, most of those commands will work with Podman too.

Now, let’s take a look at another useful command:

podman images

This lists the container images we’ve downloaded to our system.

And as you can see, our Hello World image is still here.

Even though we used --rm to automatically remove the container, that doesn’t remove the image it was created from.

Podman keeps downloaded images around so they can be reused later, without having to download them again.

But if you know you won’t need an image anymore, you can remove it.

For example:

podman rmi docker.io/library/hello-world

This removes the Hello World image from our local storage.

And if we ever need it again, Podman can simply download it again.

Now that we’ve successfully run our first container, let’s try something a little more interesting.

This time, I’m going to show you how to launch an Ubuntu container and then access a shell inside it.

This is a common example you’ll see in Docker tutorials, and it also gives us an opportunity to learn a few more Podman commands.

Here’s how we can do that:

podman run -d --name ubuntu docker.io/library/ubuntu:26.04 sleep infinity

There’s a little more going on with this command, so let’s break it down.

First, we’re using podman run, just like before.

The -d option enables what’s called detached mode, which means the container will run in the background rather than occupying our terminal.

Next, we have --name ubuntu, which assigns the name ubuntu to our container. This makes it easier to reference later, rather than having to use its container ID.

After that, we’re specifying the Ubuntu 26.04 image from Docker Hub.

And as an aside, if you’re coming to Podman from Docker, you might be used to writing a shorter image reference, like this:

podman run -d --name ubuntu ubuntu:26.04 sleep infinity

Notice that I left out the registry information.

Now, this might work on your system, but there’s something important to understand.

Unlike Docker, Podman doesn’t assume that Docker Hub is always the default registry. Instead, it uses registry configuration provided by your distribution or system administrator.

Depending on that configuration, Podman might resolve the shorter image name automatically, ask you which registry to use, or require you to specify the full image reference.

For that reason, I generally recommend including the complete image reference in your commands, especially when following tutorials.

And if you’re wondering where to find these images in the first place, Docker Hub is one of the most popular places to look. You can browse available images there and find the names and tags you need.

Now, there’s one more part of our Ubuntu command that I haven’t explained yet:

sleep infinity

This might look a little strange, but there’s a reason we’re including it.

Unlike a virtual machine, a container doesn’t normally keep running just because we’ve started it.

A container generally remains running for as long as its main process is running.

And in this example, we’re launching a basic Ubuntu environment that doesn’t automatically start a long-running application.

So we’re using sleep infinity to give the container a process that will continue running indefinitely.

That way, our Ubuntu container stays available in the background until we decide to stop it.

Now, let’s take another look at our downloaded images:

podman images

And we should see the Ubuntu image listed here.

But how do we know whether the container itself is actually running?

For that, we can use:

podman ps

This command lists our currently running containers.

We should see our Ubuntu container, along with its container ID, image, status, and other useful information.

Now that we have an Ubuntu container running, let’s actually do something with it.

We can open an interactive shell inside the container using this command:

podman exec -it ubuntu bash

Here, exec tells Podman to execute a command inside an existing container.

The -it options allow us to interact with the command through our terminal, and ubuntu is the name we assigned to our container earlier.

Finally, bash is the command we want to run inside it.

And just like that, we’re inside our Ubuntu container!

To verify that we’re actually working within Ubuntu, let’s take a look at the operating system information:

cat /etc/os-release

And we should see information identifying Ubuntu 26.04.

Now, something important to understand is that we’re not running an entire Ubuntu operating system in the same way we would with a virtual machine.

Our container has an Ubuntu userspace, but it shares the kernel of the host Linux system.

That’s one of the reasons containers are generally much more lightweight than virtual machines.

Anyway, when we’re finished working inside the container, we can press CTRL+D to exit the shell.

And notice that we’re back at our original terminal.

But our Ubuntu container is still running in the background!

That’s because exiting the shell we launched with podman exec doesn’t stop the container’s main process, which in this case is still our sleep infinity command.

So let’s look at how to stop it:

podman stop ubuntu

And if we check our running containers again:

podman ps

We’ll see that Ubuntu is no longer listed.

Now, let’s move on to something a bit more practical.

So far, we’ve launched a test container and an Ubuntu environment. But what if we want to run an actual service that we can access from another application?

For that, let’s use Nginx, which is a popular web server.

Here’s the command:

podman run -d --name web -p 8080:80 docker.io/library/nginx

Now, this command looks similar to what we used for Ubuntu, but there are a couple of important differences.

First, notice that I didn’t include sleep infinity this time.

And the reason is that we don’t need it.

Unlike our Ubuntu example, the Nginx image is specifically designed to run a web server. When we launch this container, Nginx automatically starts as its main process.

As long as that process continues running, the container stays running too.

But there’s another important difference here, and that’s this option:

-p 8080:80

This is called port publishing.

Nginx listens on port 80 inside the container, but that doesn’t automatically make the web server accessible through a port on our host.

So we’re telling Podman to publish port 8080 on our host and forward traffic from that port to port 80 inside the container.

The number on the left is the host port, and the number on the right is the container port.

And with that configured, we should now be able to access our Nginx web server through a browser.

In my case, the IP address of my Linux system is 172.16.249.105, so I’ll open:

http://172.16.249.105:8080

And there it is!

We’re now accessing a web server running inside a Podman container.

Pretty cool!

Now, before we wrap things up, I want to go over a few more commands and reinforce some of what we’ve learned.

So far, we’ve seen how to download images, launch containers, run commands inside them, and even publish a container’s network port so we can access an application through a browser.

But what about cleaning things up when we’re finished?

Let’s start by stopping our Nginx container:

podman stop web

Remember, web is the name we assigned to this container when we created it.

And if we run:

podman ps

We won’t see it listed anymore.

But that doesn’t necessarily mean the container is gone.

To demonstrate what I mean, let’s run the same command again, but this time with the -a option:

podman ps -a

This tells Podman to show all containers, including ones that are no longer running.

And as you can see, our stopped containers are still listed.

You might be wondering why Podman keeps them around after they’ve stopped.

Well, there are actually several reasons.

For example, you might want to restart a container later, inspect its configuration, or troubleshoot something that went wrong.

A stopped container retains its metadata and writable filesystem, so you can still work with it even though its main process is no longer running.

And if we wanted to start our Nginx container again, we could simply run:

podman start web

We wouldn’t need to create an entirely new container.

But let’s say we’re completely finished with it and want to remove it.

First, we’ll stop it again:

podman stop web

And then remove it:

podman rm web

Now, there’s an important distinction here that I want to emphasize.

The podman rm command removes a container, while podman rmi removes an image.

These are two different things.

Removing a container doesn’t automatically remove the image it was created from.

So if we also wanted to remove our Nginx image, we could run:

podman rmi docker.io/library/nginx

And now we’ve removed both the container and its image.

One final thing worth mentioning is the --rm option we used all the way back in our Hello World example.

If you already know that you won’t need to keep a container after it stops, you can include that option when you create it.

That way, Podman automatically removes the container when it exits, and you don’t have to clean it up manually afterward.

Just keep in mind that removing a container also removes its writable filesystem, so anything you want to preserve should be stored outside the container, such as in a volume.

And with that, we’ve covered the core fundamentals of working with Podman!

We’ve learned what Podman is, how it compares to Docker, how to run containers, how to interact with them, and how to manage their lifecycle.

Of course, there’s quite a bit more to learn.

We haven’t gotten into persistent storage, container networking in greater detail, pods, or managing containers with systemd and Quadlet.

Those are all interesting topics that deserve more attention, but I wanted this video to focus on getting you comfortable with the basics.

I’d be happy to explore some of its more advanced features in a future tutorial!

ADVERTISEMENT