Podman: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
A containerfile defines what will be in the podman image, running the image will create a container. | A containerfile defines what will be in the podman image, running the image will create a container. | ||
Podman containterfiles have the same syntax as dockerfiles. The podman build command looks first for Containerfile and then for Dockerfile in the specified directory. | |||
=Basics= | =Basics= | ||
| Line 34: | Line 34: | ||
:Return the whole image specification as json-string | :Return the whole image specification as json-string | ||
;<nowiki>podman run -v <hostdir>:<containerdir> -it <image ID> bash</nowiki> | ;<nowiki>podman run -v <hostdir>:<containerdir> --rm -it <image ID> bash</nowiki> | ||
:Create the container and open a bash prompt in it (as root user). When leaving the shell the container is closed | :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. | :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 | :<hostdir> is mounted on <containerdir> which will be created automatically. | ||
;podman run --rm <image ID> | :NOTE: <hostdir> should not be a NFS filesystem, the container has no access to that. | ||
: | ;podman run -it --network=host <image ID> | ||
:You will enter the container with the network settings (interface, hostname,...) from the host system. This enables mailing from the container. | |||
;podman run --rm <image ID> <command> | |||
:Run <command> in the container, remove the container on exit, | |||
;podman exec -it <containerid> <command> | |||
:Run <command> in a running container, -it is needed for interactive commands like bash | |||
;podman stop <containerID> | |||
:Stop a container | |||
;podman rm <containerID> | |||
:Remove a container | |||
;podman image rm <imageID> | |||
:Remove an image | |||
;podman ps -a | ;podman ps -a | ||
| Line 53: | Line 63: | ||
==FROM== | ==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 | ;FROM <Imagelocation> | ||
: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 | ;podman search docker.io/library/nginx | ||
:List all images for nginx | :List all images for nginx | ||
==RUN== | ==RUN== | ||
Specify a command to run when the images is build. You can have a whole lot of these. | ;RUN <command> | ||
:Specify a command to run when the images is build. You can have a whole lot of these. | |||
==CMD== | ==CMD== | ||
Command to run when the container starts | ;CMD <command> | ||
:Command to run when the container starts | |||
==LABEL== | ==LABEL== | ||
;LABEL name="My Name" | |||
:Give the container a label. You can have several labels of a container. | |||
==COPY== | |||
;COPY <localfile> <containerpath> | |||
:Copy <localfile>, that must be in Containerfile directory, to <containerpath> | |||
=Full-fledged | =Full-fledged container= | ||
==Containerfile== | ==Containerfile== | ||
| Line 76: | Line 93: | ||
LABEL maintainer="Hans de Ridder" | LABEL maintainer="Hans de Ridder" | ||
RUN apt-get update | RUN apt-get update | ||
RUN apt-get -y install less joe vim | RUN apt-get -y install less joe vim exim4 procps | ||
RUN apt-get -y install python3-full | RUN apt-get -y install python3-full | ||
RUN python3 -m venv /opt/python/venv | RUN python3 -m venv /opt/python/venv | ||
ENV PATH="/opt/python/venv/bin:$PATH" | ENV PATH="/opt/python/venv/bin:$PATH" | ||
RUN pip install pandas | RUN pip install pandas | ||
COPY update-exim4.conf.conf /etc/exim4/ | |||
RUN update-exim4.conf | |||
CMD ["bash", "-i"] | CMD ["bash", "-i"] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 88: | Line 107: | ||
: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. If the container is already running you will be in the same shell. | :Re-enter the container after you left it. If the container is already running you will be in the same shell. | ||
Latest revision as of 12:50, 14 January 2026
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.
Podman 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> --rm -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.
- NOTE: <hostdir> should not be a NFS filesystem, the container has no access to that.
- podman run -it --network=host <image ID>
- You will enter the container with the network settings (interface, hostname,...) from the host system. This enables mailing from the container.
- podman run --rm <image ID> <command>
- Run <command> in the container, remove the container on exit,
- podman exec -it <containerid> <command>
- Run <command> in a running container, -it is needed for interactive commands like bash
- podman stop <containerID>
- Stop a container
- podman rm <containerID>
- Remove a container
- podman image rm <imageID>
- Remove an image
- 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 <Imagelocation>
- 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
- RUN <command>
- Specify a command to run when the images is build. You can have a whole lot of these.
CMD
- CMD <command>
- Command to run when the container starts
LABEL
- LABEL name="My Name"
- Give the container a label. You can have several labels of a container.
COPY
- COPY <localfile> <containerpath>
- Copy <localfile>, that must be in Containerfile directory, to <containerpath>
Full-fledged 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 exim4 procps
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
COPY update-exim4.conf.conf /etc/exim4/
RUN update-exim4.conf
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.