13.6 C
Jaipur
Sunday, January 23, 2022

How to Install Podman as Docker alternative on Debian 11

Must read

Podman (the POD MANager) is an OCI-compliant container engine, developed by Red Hat as a drop-in replacement of Docker. It is used to manage and run, containers, images, and volumes via a command-line interface. Both Docker and Podman are similar software. The only difference is that Podman doesn’t require a daemon to run containers, while Docker needs the Docker Engine daemon. Podman uses the libpod library to manage an entire container ecosystem.

In this tutorial, we will show you how to install and use Podman on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A root password is configured on the server.

Install Podman

The Podman package is included in the Debian 11 default repository. You can install it by just running the following command:

apt-get install podman -y

Once the Podman is installed, verify the Podman version using the command below:

podman --version

You should see the Podman version in the following output:

podman version 3.0.1

You can get more information of Podman using the following command:

podman info

You will get the following output:

host:
  arch: amd64
  buildahVersion: 1.19.6
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: 'conmon: /usr/bin/conmon'
    path: /usr/bin/conmon
    version: 'conmon version 2.0.25, commit: unknown'
  cpus: 2
  distribution:
    distribution: debian
    version: "11"
  eventLogger: journald
  hostname: debian11
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.10.0-8-amd64
  linkmode: dynamic
  memFree: 3365183488
  memTotal: 4122267648
  ociRuntime:
    name: crun
    package: 'crun: /usr/bin/crun'
    path: /usr/bin/crun
    version: |-
      crun version 0.17
      commit: 0e9229ae34caaebcb86f1fde18de3acaf18c6d9a
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +YAJL
  os: linux
  remoteSocket:
    exists: true
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: true
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    selinuxEnabled: false

Add OCI Registry

Podman uses the registry configuration file /etc/containers/registries.conf to pull all container images from the internet. So you will need to edit it and define the registry:

nano /etc/containers/registries.conf

Add the following lines at the end of the file:

[registries.insecure]
registries = [ ]
# If you need to block pull access from a registry, uncomment the section below
# and add the registries fully-qualified name.
# Docker only
[registries.block]
registries = [ ]

Save and close the file when you are finished.

How to Use Podman

In this section, we will show you how to use the Podman command to pull images and run a container.

To pull a Debian image, run the following command:

podman pull debian

You will get the following output:

Resolved "debian" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull docker.io/library/debian:latest...
Getting image source signatures
Copying blob 647acf3d48c2 done  
Copying config 827e561138 done  
Writing manifest to image destination
Storing signatures
827e5611389abf13dad1057e92f163b771febc0bcdb19fa2d634a7eb0641e0cc

You can see your downloaded image using the following command:

podman images

You will get the following output:

REPOSITORY                TAG     IMAGE ID      CREATED      SIZE
docker.io/library/debian  latest  827e5611389a  11 days ago  129 MB

Next, run a container from the Debian image using the following command:

podman run -dit debian:latest

You will get the following output:

f85c4df5ab787912c984ec820571da7b95b32736ef94ba691d9ab5019c5b5103

You can list all running containers using the following command:

podman ps

You should see the following output:

CONTAINER ID  IMAGE                            COMMAND  CREATED         STATUS             PORTS   NAMES
f85c4df5ab78  docker.io/library/debian:latest  bash     13 seconds ago  Up 13 seconds ago          competent_cori

To inspect the running container, run the Podman command by specifying container ID:

podman inspect f85c4df5ab78

You will get the following output:

[
    {
        "Id": "f85c4df5ab787912c984ec820571da7b95b32736ef94ba691d9ab5019c5b5103",
        "Created": "2021-11-28T07:00:12.795302341Z",
        "Path": "bash",
        "Args": [
            "bash"
        ],
        "State": {
            "OciVersion": "1.0.2-dev",
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 6881,
            "ConmonPid": 6878,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-11-28T07:00:13.551753552Z",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Healthcheck": {
                "Status": "",
                "FailingStreak": 0,
                "Log": null
            }
        },

To check the container log, run the following command:

podman logs f85c4df5ab78

If you want to connect to the running container, run the following command:

podman exec -it f85c4df5ab78 /bin/bash

You will get into the container shell as shown below:

[email protected]:/#

To exit from the container shell, run the following command:

[email protected]:/# exit

How to Stop and Remove a Container

You can also use Podman to start, stop, and remove a container.

To stop a running container, run the following command:

podman stop f85c4df5ab78

You can now verify the stopped container using the following command:

podman ps -a

You should see the following output:

CONTAINER ID  IMAGE                            COMMAND  CREATED        STATUS                       PORTS   NAMES
f85c4df5ab78  docker.io/library/debian:latest  bash     3 minutes ago  Exited (137) 10 seconds ago          competent_cori

To remove a stopped container, run the following command:

podman rm f85c4df5ab78

If you want to stop the latest container, run the following command:

podman stop --latest

To start the latest container, run the following command:

podman start --latest

To remove the latest container, run the following command:

podman rm --latest

To remove all running containers, run the following command:

podman rm -f `podman ps -aq`

To remove an image, run the following command:

podman rmi 827e5611389a

You will get the following output:

Untagged: docker.io/library/debian:latest
Deleted: 827e5611389abf13dad1057e92f163b771febc0bcdb19fa2d634a7eb0641e0cc

Conclusion

In the above post, we explained how to install and use the Podman on Debian 11. You can now use the Podman as a replacement of Docker to run and manage the containers.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -

Latest article