Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

How To run Docker Containers using Podman and Libpod

The Docker command-line interface is a client/server operation. The command line communicates with the Docker engine whenever it wants to create or manipulate the operations of a container.  In this guide, you will learn how to how to run docker containers using podman and libpod. Check out our previous guide on how to install Podman on CentOS 8.

Podman

Podman exists to offer a daemonless container engine for managing containers on a Linux system. Podman works with pods, in a similar fashion to Kubernetes. Podman manages pods, containers, container images and volumes.

Docker vs Podman

The major difference between Docker and Podman is in their architecture. Whilst Docker is a systemd daemon,  Podman is not.

Libpod

Libpod provides a library for running OCI based containers in pods.

In this article you will learn how to run and manage containers using docker.

Managing Container Images

To pull an image using Podman run the commands as shown below with the name of the desired image.

$ podman pull centos

To view the   list  of downloaded images, execute the command:

$ podman images

To remove an image, use -rmi option followed by image name or image ID:

$ podman rmi 300e315adb2f

Tagging images

Tagging an image is adding  your custom name to images to make them more intuitive and to remind you what the image does in your set up

$ podman tag 33c4a622f37c virtualserver

Running Containers with Podman

To run a container using an Ubuntu image that prints out a message on the screen, run the command below: 

$ podman run --rm ubuntu /bin/echo “Welcome to Podman!”

To run a container in  the background /detached mode, use -d option.

 podman run -dt -p 8080:8080/tcp -e HTTPD_VAR_RUN=/var/run/httpd -e HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \
                   -e HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \
                   -e HTTPD_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/httpd/ \ 

This will return the container ID:

Listing running containers

The podman ps command is used to list the running containers.

$ podman ps

Run a shell in a container

To access a container shell, run the command below with the -it option

$ podman run -it ubuntu bash

Searching in Podman

To search for images hosted on Docker, use the search command as shown

$ podman search fedora

Inspecting Containers

The podman inspect command prints low-level information  about the container specified by name or ID .

To inspect an image, use the podman inspect command followed by container ID

$ podman inspect 33c4a622f37c

Removing containers

To remove containers,  first list all the available containers by running the command:

$ podman ps -a

To delete a single  container use the podman rm command followed by the container id:

$ podman rm 33c4a622f37c

To delete all containers, both running and stopped run the command:

$ podman rm $(podman ps -a -q)

Viewing the container’s logs

 To view the container’s logs use the podman logs command. To view the latest logs run:

$ podman logs --latest

 To view the container’s logs of a specific container run:

$ podman logs b6c70797c6c6

To follow the logs output in real-time, execute:

$ podman logs -f  ContainerID
$ podman logs --follow=true --since 10m ContainerID

To show only the  last 10 lines in logs run: podman logs –tail 10 followed by the container ID

$ podman logs --tail 10 b6c70797c6c6

Viewing the container’s pids

To view the container’s pids use:

$ podman top <container_id>

Managing  Container pods with Podman

Interaction with pods is exposed through the podman pod command.

To view the available options with the podman pod command use:

$ podman pod --help

To create a pod called server run:

$ podman pod create --name server

Make sure pod is created:

$ podman pod list

Upon creating a new pod, you will notice that it has  a container called infra. Infra accommodates namespaces associated with the pod allowing  the pod to communicate with other containers.

$ podman ps -a --pod

To add a container to a pod run:

$ podman run -dt --pod server centos:latest top

You’ll see that the pod has two containers.

Conclusion

With the steps above, you have learned how to run docker containers using podman and libpod.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x