Using Podman creating and managing containers, and handling images

Podman is a container management tool that serves as an alternative to Docker, offering similar functionalities without requiring a daemon.

# mac
$ brew install podman
$ podman machine init
$ podman machine start

Since podman is compatible with the Docker command, you can set an alias for convenient use.

alias docker=podman

Let's test using CentOS.

$ podman run -it centos
# OR if you have the alias
$ docker run -it centos

Basic commands

# Container process list
$ podman ps -a

# Container start/stop
$ podman start {ID}
$ podman stop {ID}

# Container remove
$ podman rm {ID}

# Cintainer images
$ podman images

You can save the current state of the container as a checkpoint and restore it later.

$ podman container checkpoint --leave-running --export=/path/to/backup.tar my_container
$ podman stop my_container
$ podman rm my_container
$ podman container restore --import=/path/to/backup.tar

Container image build

If there is a Dockerfile in the current working directory, you can build a container image with the Build command.

$ podman build -t myProject/myContainer .

 

Container image pull

You can use the pull command to retrieve container images from Docker Hub or other registries.

# pull image
$ podman pull ubuntu

# remove image
$ podman rmi {ID}

Pod related commands

# Pod create
$ podman pod create --name my-pod

# Pod list
$ podman pod ls
$ podman ps -a --pod

# add Pod in a Container
$ podman run -dt --pod my-pod myContainer

# Pod start/stop
$ podman pod start {ID}
$ podman pod stop {ID}
$ podman pod rm {ID}

# K8s distribution
$ podman generate kube {Name}
# Distribute to Kubernetes
$ kubectl create -f podman-generated.yaml
$ kubectl get pod
$ kubectl describe pod {Name}

systemd generate

By using systemd, you can create and manage containers as services, each managed individually.

# 1. Create a normal container
$ podman run -d --name redis_server -p 6379:6379 redis

# 2-1. create systemd service file
$ vi /etc/systemd/system/redis_server.service
[Unit]
Description=Redis container

[Service]
Restart=always
ExecStart=/usr/bin/podman start -a redis_server
ExecStop=/usr/bin/podman stop -t 2 redis_server

[Install]
WantedBy=local.target

# 2-2. OR use generate command
$ podman generate systemd redis_server  > /etc/systemd/system/redis_server.service

# Container Start/Stop
$ systemctl start redis-container.service
$ systemctl status redis-container.service
$ systemctl stop redis-container.service
$ systemctl status redis-container.service

 

Tags: 
sean's picture

Language

Get in touch with us

"If you would thoroughly know anything, teach it to other."
- Tryon Edwards -