Skip to content

Running Containers

Now that you understand what containers are, it is time to run one. This page walks through the most common Podman commands you will use day to day.

The podman run command pulls an image and starts a container from it. Try it with the hello-world image:

Terminal window
$ podman run hello-world

Podman downloads the image, creates a container, runs it, and prints a welcome message. The container then stops on its own.

You can also run a full operating system image like Ubuntu:

Terminal window
$ podman run ubuntu:24.04

This pulls Ubuntu 24.04, starts a container, and exits immediately. It exits because no command was given for the container to run. The next section shows how to keep it open.

Use -it to start a container and get a shell inside it:

Terminal window
$ podman run -it ubuntu:24.04 bash

The -i flag keeps standard input open. The -t flag allocates a terminal. Together they give you an interactive session inside the container.

Once inside, you can explore the container’s file system:

Terminal window
root@a1b2c3d4e5f6:/# ls /
root@a1b2c3d4e5f6:/# cat /etc/os-release
root@a1b2c3d4e5f6:/# exit

Typing exit stops the container and returns you to your host terminal.

Sometimes you want to run a single command and clean up afterward. The --rm flag removes the container automatically after it stops:

Terminal window
$ podman run --rm ubuntu:24.04 echo "hello from the container"

Without --rm, stopped containers remain on disk. They accumulate over time and waste space. Using --rm is a good habit for one-off commands.

BioContainers provides pre-built images for thousands of bioinformatics tools. You do not need to install anything on your host system. Just pull and run.

Check the version of samtools:

Terminal window
$ podman run --rm biocontainers/samtools:v1.17.0_cv1 samtools --version

Run FastQC on a FASTQ file:

Terminal window
$ podman run --rm -v $(pwd):/data biocontainers/fastqc:v0.12.1_cv1 fastqc /data/reads.fastq.gz

The -v flag mounts your current directory into the container. This lets the tool access your files. Volumes are covered in detail in the next chapter.

Some containers need to run continuously. An RStudio Server instance is a good example. Use -d to run in detached mode:

Terminal window
$ podman run -d -p 8787:8787 -e PASSWORD=mypassword rocker/rstudio:latest

The -d flag runs the container in the background. The -p flag maps port 8787 on your host to port 8787 in the container. You can then open http://localhost:8787 in your browser.

Podman prints the container ID when it starts in detached mode. You will use this ID to manage the container.

To see all running containers:

Terminal window
$ podman ps

To see all containers, including stopped ones:

Terminal window
$ podman ps -a

The output shows each container’s ID, image, status, and name. Podman assigns a random name if you do not provide one. You can set a name with --name:

Terminal window
$ podman run -d --name rstudio -p 8787:8787 -e PASSWORD=mypassword rocker/rstudio:latest

Stop a running container by name or ID:

Terminal window
$ podman stop rstudio

This sends a graceful shutdown signal. The container has 10 seconds to stop before Podman forces it to stop.

Remove a stopped container:

Terminal window
$ podman rm rstudio

To force-remove a running container in one step:

Terminal window
$ podman rm -f rstudio

To remove all stopped containers at once:

Terminal window
$ podman container prune

Containers write their standard output and standard error to a log. View it with podman logs:

Terminal window
$ podman logs rstudio

To follow the log in real time, add -f:

Terminal window
$ podman logs -f rstudio

This is useful for debugging. If a bioinformatics tool fails inside a container, the error message will be in the logs.

You can open a shell inside a container that is already running. This is helpful for inspecting files or debugging:

Terminal window
$ podman exec -it rstudio bash

The exec command runs a new process inside an existing container. The -it flags work the same as with podman run. They give you an interactive terminal.

You can also run a single command without opening a full shell:

Terminal window
$ podman exec rstudio ls /home/rstudio
Command Description
podman run image Run a container from an image
podman run -it image bash Run interactively with a shell
podman run --rm image cmd Run and remove after exit
podman run -d image Run in the background
podman run -v host:container Mount a host directory
podman ps List running containers
podman ps -a List all containers
podman stop name Stop a container
podman rm name Remove a stopped container
podman rm -f name Force-remove a container
podman logs name View container logs
podman exec -it name bash Open a shell in a running container

You now know how to run, inspect, and manage containers. The next chapter covers Volumes and Networking, where you will learn how to share data between your host and containers.