Podman: Difference between revisions

From wiki
Jump to navigation Jump to search
Created page with "Category:Linux/Unix Podman is used to create containers, like Docker. In a container system resources are separated from each other e.g. to create a development environment where the developer can experiment freely without the risk of jeopardizing the host system. The main difference is podman does not need a daemon like docker. It is lighter and more secure [https://www.geeksforgeeks.org/devops/podman-vs-docker/#podman-vs-docker-a-detailed-comparison] A contai..."
 
No edit summary
Line 9: Line 9:


=Basics=
=Basics=
;Installation:
;apt install podman
apt install podman
:Install podman


;This creates a working container with a python virtual environment
;This containerfile creates a working container with a python virtual environment
:Containerfile
<syntaxhighlight lang=text>
<syntaxhighlight lang=text>
FROM debian
FROM debian
Line 66: Line 65:


==LABEL==
==LABEL==
Give the container a label specify like <code>LABEL name="My Name"</code>. You can have several labels of a container.
Give the container a label, specify like <code>LABEL name="My Name"</code>. You can have several labels of a container.


=Full-fledged interactive container=
=Full-fledged interactive container=
Line 72: Line 71:
==Containerfile==
==Containerfile==


<syntaxhighlight land=text>
<syntaxhighlight lang=text>
FROM docker.io/library/debian
FROM docker.io/library/debian
LABEL name="Full-fledged debian image"
LABEL name="Full-fledged debian image"
Line 87: Line 86:
==Usage==
==Usage==
;podman build -t debian <directory>
;podman build -t debian <directory>
;Build the image
:Build the image
;podman run -it --name FF <image ID>
;podman run -it --name FF <image ID>
:You will enter the container
:You will enter the container
;podman start -ia FF
;podman start -ia FF
:Re-enter the container after you left it.
:Re-enter the container after you left it. If the container is already running you will be in the same shell.

Revision as of 11:38, 25 July 2025

Podman is used to create containers, like Docker. In a container system resources are separated from each other e.g. to create a development environment where the developer can experiment freely without the risk of jeopardizing the host system.

The main difference is podman does not need a daemon like docker. It is lighter and more secure [1]

A containerfile defines what will be in the podman image, running the image will create a container.

Podamn containterfiles have the same syntax as dockerfiles. The podman build command looks first for Containerfile and then for Dockerfile in the specified directory.

Basics

apt install podman
Install podman
This containerfile creates a working container with a python virtual environment
FROM debian
LABEL name="Hans de Ridder"
RUN apt-get update
RUN apt-get -y install python3-full
RUN python3 -m venv /home/ubuntu/venv
ENV PATH="/home/ubuntu/venv/bin:$PATH"
RUN pip install pandas
CMD ["echo", "I'm alive"]
podman build -t <name>:<tag> <directory>
This builds the image with a name and a tag
podman pull <registry image>
Create an image from the registry image (see #FROM)
podman image ls
List all existing images
podman image inspect <image ID>
Return the whole image specification as json-string
podman run -v <hostdir>:<containerdir> -it <image ID> bash
Create the container and open a bash prompt in it (as root user). When leaving the shell the container is closed
This way you can run any command in a container that only exists while the command is running.
<hostdir> is mounted on <containerdir> which will be created automatically
podman run --rm <image ID>
Delete the image on exit


podman ps -a
List all containers
podman system prune
Delete unused images and build caches
podman system prune -a
Delete unused images and all build caches

Containerfile commands

FROM

FROM: Specifies what is the base-image. Images are on a registry server like docker.io. You can use aliases like ubuntu or debian but that is not advised as you cannot be 100% sure where the images will be coming from. Therefor it is advised to user the full image path like docker.io/library/debian

podman search docker.io/library/nginx
List all images for nginx

RUN

Specify a command to run when the images is build. You can have a whole lot of these.

CMD

Command to run when the container starts

LABEL

Give the container a label, specify like LABEL name="My Name". You can have several labels of a container.

Full-fledged interactive container

Containerfile

FROM docker.io/library/debian
LABEL name="Full-fledged debian image"
LABEL maintainer="Hans de Ridder"
RUN apt-get update
RUN apt-get -y install less joe vim
RUN apt-get -y install python3-full
RUN python3 -m venv /opt/python/venv
ENV PATH="/opt/python/venv/bin:$PATH"
RUN pip install pandas
CMD ["bash", "-i"]

Usage

podman build -t debian <directory>
Build the image
podman run -it --name FF <image ID>
You will enter the container
podman start -ia FF
Re-enter the container after you left it. If the container is already running you will be in the same shell.