Podman

https://www.notion.so/Podman-6c02911b97b64ff8b44af35eb4019674

The alternative of docker as docker is no longer free for enterprise users.

Installation

bookmark

Install from download

1
2
3
4
wget https://github.com/containers/podman/releases/latest/download/podman-remote-static-linux_amd64.tar.gz
tar -xvzf podman-remote-static-linux_amd64.tar.gz
sudo mv ./bin/podman-remote-static-linux_amd64 /usr/local/bin/podman
sudo chmod +x /usr/local/bin/podman

Examples

1
2
3
4
5
# If you want to keep your existing volumns, you should use --userns=keep-id,
# otherwise, it might throw "operation not permitted" when start a container
podman run -d --name my-container --userns=keep-id \
    -v /your-path:/path
	image-name

Configure sources

Open /etc/containers/registries.conf and uncomment below line, so that you can pull images from other sources.

1
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "docker.io"]

Jenkins in Podman

Run podman in jenkins pipeline if jenkins is running in container

Mount the socket of podman into jenkins container.

1
2
3
4
5
6
docker run -d \
  --name my-jenkins \
  -p 8080:8080 \
  -v /home/<host_user>/jenkins_home:/var/jenkins_home \
  -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock \
  bndynet/jenkins

Then run it in pipeline:

1
2
3
4
5
6
7
8
9
10
11
pipeline {
    agent any
    stages {
        stage('Run Podman') {
            steps {
                sh 'export PODMAN_HOST=unix:///run/user/1000/podman/podman.sock && podman run --rm hello-world'
            }
        }
    }
}

Let jenkins account run podman

1
sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 jenkins

If the jenkins user does not exist, please create one:

1
2
sudo useradd -m -s /bin/bash jenkins
sudo passwd jenkins  # set password(optional)

Restart jenkins

1
2
sudo systemctl restart jenkins
# or podman restart jenkins-container

Automatically Start

Podman provides generate systemd command, that can generate systemd service file to restart when server starts.

1
2
podman generate systemd --name my-container --restart-policy=always > /etc/systemd/system/my-container.service

Then enable and start service:

1
2
3
systemctl daemon-reload
systemctl enable my-container
systemctl start my-container

In this way, my-container will start automatically, it likes docker –restart unless-stopped.

Q&A

Can not “podman machine start”?

You need to remove the current machine via podman machine rm. and reinit via podman machine init.

This post is licensed under CC BY 4.0 by the author.