### Enable container on boot with [Install] section Source: https://docs.podman.io/en/latest/_sources/markdown/podman-systemd.unit.5.md.txt Adds the [Install] section to a Quadlet unit file to start the container on boot. Only Alias, WantedBy, RequiredBy, and UpheldBy keys are supported. ```ini [Install] WantedBy=default.target ``` -------------------------------- ### Start a podman machine with default output Source: https://docs.podman.io/en/latest/_sources/markdown/podman-machine-start.1.md.txt Starts the specified machine (myvm) and displays the startup output, including rootless mode notice, API forwarding socket path, and instructions for installing the system helper service and setting DOCKER_HOST. ```bash $ podman machine start myvm Starting machine "myvm" This machine is currently configured in rootless mode. If your containers require root permissions (e.g. ports < 1024), or if you run into compatibility issues with non-podman clients, you can switch using the following command: podman machine set --rootful myvm API forwarding listening on: /var/folders/my/k1kpd8ds7p938mchyb1r_4mw0000gn/T/podman/myvm-api.sock The system helper service is not installed; the default Docker API socket address can't be used by podman. If you would like to install it, run the following commands: sudo /opt/homebrew/Cellar/podman/5.2.4/bin/podman-mac-helper install podman machine stop myvm; podman machine start myvm You can still connect Docker API clients by setting DOCKER_HOST using the following command in your terminal session: export DOCKER_HOST='unix:///var/folders/my/k1kpd8ds7p938mchyb1r_4mw0000gn/T/podman/myvm-api.sock' Machine "myvm" started successfully ``` -------------------------------- ### Pod with one-shot startup task example Source: https://docs.podman.io/en/latest/_sources/markdown/podman-systemd.unit.5.md.txt Example for a Pod with a one-shot startup task. The pod unit sets ExitPolicy to continue, the startup-task container runs a one-shot setup, and the app container depends on the startup task. ```ini [Pod] PodName=test ExitPolicy=continue ``` ```ini [Service] Type=oneshot RemainAfterExit=yes [Container] Pod=test.pod Image=quay.io/centos/centos:latest Exec=sh -c "echo 'setup starting'; sleep 2; echo 'setup complete'" ``` ```ini [Unit] Requires=startup-task.container After=startup-task.container [Container] Pod=test.pod Image=quay.io/centos/centos:latest Exec=sh -c "echo 'app running.'; sleep 30" ``` -------------------------------- ### Enable container on boot with WantedBy=multi-user.target Source: https://docs.podman.io/en/latest/_sources/markdown/podman-container.unit.5.md.txt Include an [Install] section with WantedBy=multi-user.target to ensure the container starts on boot. Only Alias=, WantedBy=, RequiredBy=, and UpheldBy= keys are supported. ```ini [Install] WantedBy=multi-user.target ``` -------------------------------- ### Install Quadlet from a URL Source: https://docs.podman.io/en/latest/_sources/markdown/podman-quadlet-install.1.md.txt Installs a Quadlet file from a web URL. The output shows the installed unit file path. ```bash $ podman quadlet install https://github.com/containers/podman/blob/main/test/e2e/quadlet/basic.container /home/user/.config/containers/systemd/basic.container ``` -------------------------------- ### Start a podman machine with --no-info Source: https://docs.podman.io/en/latest/_sources/markdown/podman-machine-start.1.md.txt Starts the machine myvm while suppressing informational tips, showing only the starting and success messages. ```bash $ podman machine start --no-info myvm Starting machine "myvm" Machine "myvm" started successfully ``` -------------------------------- ### Start webserver.service Source: https://docs.podman.io/en/latest/_sources/markdown/podman-quadlet-basic-usage.7.md.txt Deploy the web server container. ```bash cp webserver.container ~/.config/containers/systemd/ systemctl --user daemon-reload systemctl --user start webserver.service ``` ```bash sudo cp webserver.container /etc/containers/systemd/ sudo systemctl daemon-reload sudo systemctl start webserver.service ``` -------------------------------- ### Example: sleep@10.container.d/10-image.conf drop-in Source: https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html Drop-in file to customize a template instance. Create it as sleep@10.container.d/10-image.conf without a sleep@10.container file or symlink. Inherits the template's [Install] settings, so this instance also starts at boot. ```ini [Container] Image=quay.io/centos/centos ``` -------------------------------- ### Install s3fs-fuse Source: https://docs.podman.io/en/latest/markdown/podman-volume-create.1.html Installs s3fs-fuse on Fedora using doas. Required before using s3fs or the podman volume examples. ```bash $ doas dnf install s3fs-fuse ``` -------------------------------- ### Examples of podman machine ssh usage Source: https://docs.podman.io/en/latest/_sources/markdown/podman-machine-ssh.1.md.txt Examples from the EXAMPLES section. The first starts an interactive session with the default machine, the second runs a command inside the default machine, and the third runs a command inside a specified machine. ```console $ podman machine ssh ``` ```console $ podman machine ssh myvm ``` ```console $ podman machine ssh myvm rpm -q podman ``` -------------------------------- ### Initialize and start Podman machine in one step Source: https://docs.podman.io/en/latest/_sources/markdown/podman-machine-init.1.md.txt Initializes and starts a new Podman machine in one step using the --now flag. ```bash $ podman machine init --now ``` -------------------------------- ### Assemble and push multi-arch manifest from separately built images Source: https://docs.podman.io/en/latest/_sources/markdown/podman-manifest.1.md.txt Creates a manifest list from images tagged by architecture, adds each image with 'podman manifest add', then pushes with --all. The add argument order is then , and --all is required to push all contents. ```bash $ REPO=example.com/example/shazam $ podman manifest create $REPO:latest $ for IMGTAG in amd64 s390x ppc64le arm64; do \ podman manifest add $REPO:latest docker://$REPO:IMGTAG; \ done $ podman manifest push --all $REPO:latest ``` -------------------------------- ### Example test.container with Quadlet Source: https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html Example test.container file using Quadlet. Defines a minimal container with Image, Volume, Network, and Exec settings, plus systemd [Service] and [Install] sections. ```ini [Unit] Description=A minimal container [Container] # Use the centos image Image=quay.io/centos/centos:latest # Use volume and network defined below Volume=test.volume:/data Network=test.network # In the container we just run sleep Exec=sleep 60 [Service] # Restart service when sleep finishes Restart=always # Extend Timeout to allow time to pull the image TimeoutStartSec=900 # ExecStartPre flag and other systemd commands can go here, see systemd.unit(5) man page. ExecStartPre=/usr/share/mincontainer/setup.sh [Install] # Start by default on boot WantedBy=multi-user.target default.target ``` -------------------------------- ### Run the built hello image with podman run Source: https://docs.podman.io/en/latest/Introduction.html Run the newly built hello image locally with `podman run -it hello`. The output displays a welcome message and project links. ```bash podman run -it hello ``` ```text !... Hello Podman World ...! .--"--. / - - \ / (O) (O) \ ~~~| -=(,Y,)=- | .---. /` \ |~~ ~/ o o \~~~~.----. ~~ | =(X)= |~ / (O (O) \ ~~~~~~~ ~| =(Y_)=- | ~~~~ ~~~| U |~~ Project: https://github.com/containers/podman Website: https://podman.io Desktop: https://podman-desktop.io Documents: https://docs.podman.io YouTube: https://youtube.com/@Podman X/Twitter: @Podman_io Mastodon: @Podman_io@fosstodon.org ``` -------------------------------- ### Example: sleep@.container template Source: https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html Template Quadlet file for a sleep container. The %i specifier is replaced with the instance name. DefaultInstance=100 enables that instance at boot. Instances can be started with systemctl start sleep@50.service. ```ini [Unit] Description=A templated sleepy container [Container] Image=quay.io/fedora/fedora Exec=sleep %i [Service] # Restart service when sleep finishes Restart=always [Install] WantedBy=multi-user.target DefaultInstance=100 ``` -------------------------------- ### Start with-volume.service Source: https://docs.podman.io/en/latest/_sources/markdown/podman-quadlet-basic-usage.7.md.txt Deploy and check the status of the container using the volume. ```bash cp with-volume.container ~/.config/containers/systemd/ systemctl --user daemon-reload systemctl --user start with-volume.service systemctl --user status with-volume.service ``` ```bash sudo cp with-volume.container /etc/containers/systemd/ sudo systemctl daemon-reload sudo systemctl start with-volume.service sudo systemctl status with-volume.service ``` -------------------------------- ### Start a Podman machine named myvm Source: https://docs.podman.io/en/latest/markdown/podman-machine-start.1.html Starts the virtual machine named myvm. The output includes warnings about rootless mode, API forwarding socket path, and instructions for Docker API compatibility if the system helper service is not installed. ```console $ podman machine start myvm Starting machine "myvm" This machine is currently configured in rootless mode. If your containers require root permissions (e.g. ports < 1024), or if you run into compatibility issues with non-podman clients, you can switch using the following command: podman machine set --rootful myvm API forwarding listening on: /var/folders/my/k1kpd8ds7p938mchyb1r_4mw0000gn/T/podman/myvm-api.sock The system helper service is not installed; the default Docker API socket address can't be used by podman. If you would like to install it, run the following commands: sudo /opt/homebrew/Cellar/podman/5.2.4/bin/podman-mac-helper install podman machine stop myvm; podman machine start myvm You can still connect Docker API clients by setting DOCKER_HOST using the following command in your terminal session: export DOCKER_HOST='unix:///var/folders/my/k1kpd8ds7p938mchyb1r_4mw0000gn/T/podman/myvm-api.sock' Machine "myvm" started successfully ``` -------------------------------- ### Start webserver.service for rootless and rootful Source: https://docs.podman.io/en/latest/markdown/podman-quadlet-basic-usage.7.html Commands to copy the webserver.container file, reload systemd, and start the webserver.service for rootless and rootful configurations. After starting, visit http://localhost:8080. ```bash cp webserver.container ~/.config/containers/systemd/ systemctl --user daemon-reload systemctl --user start webserver.service ``` ```bash sudo cp webserver.container /etc/containers/systemd/ sudo systemctl daemon-reload sudo systemctl start webserver.service ``` -------------------------------- ### Create the volume service Source: https://docs.podman.io/en/latest/_sources/markdown/podman-quadlet-basic-usage.7.md.txt Start the service to initialize the volume. ```bash systemctl --user start mydata-volume.service ``` ```bash systemctl start mydata-volume.service ``` -------------------------------- ### Generated systemd unit file for a container Source: https://docs.podman.io/en/latest/_sources/markdown/podman-generate-systemd.1.md.txt Example of a systemd unit file generated by Podman 1.8.0 for a container. It starts the container with `podman start` and stops it with `podman stop -t 1`. The service uses `Type=forking` and a PID file. ```ini # container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service # autogenerated by Podman 1.8.0 # Wed Mar 09 09:46:45 CEST 2020 [Unit] Description=Podman container-de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6.service Documentation=man:podman-generate-systemd(1) Wants=network-online.target After=network-online.target RequiresMountsFor=/var/run/container/storage [Service] Restart=always ExecStart=/usr/bin/podman start de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6 ExecStop=/usr/bin/podman stop \ -t 1 de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6 KillMode=none Type=forking PIDFile=/run/user/1000/overlay-containers/de1e3223b1b888bc02d0962dd6cb5855eb00734061013ffdd3479d225abacdc6/userdata/conmon.pid [Install] WantedBy=default.target ``` -------------------------------- ### cURL example: podman info Source: https://docs.podman.io/en/latest/_static/api.html Sends a GET request to the Libpod API endpoint for `podman info` using the Unix socket. ```bash curl --unix-socket /run/podman/podman.sock http://d/v6.0.0/libpod/info ``` -------------------------------- ### Initialize default Podman machine with USB device passthrough (vendor/product) Source: https://docs.podman.io/en/latest/_sources/markdown/podman-machine-init.1.md.txt Initializes the default Podman machine with a USB device passthrough specified with vendor and product options. Only supported for QEMU machines. ```bash $ podman machine init --usb vendor=13d3,product=5406 ``` -------------------------------- ### Filter list by name Source: https://docs.podman.io/en/latest/markdown/podman-quadlet-list.1.html Filters the quadlet list by name using the `--filter` option with a pattern. The example shows filtering for names starting with 'test'. ```bash $ podman quadlet list --filter 'name=test*' NAME UNIT NAME PATH ON DISK STATUS APPLICATION POD test-service-quadlet.container test-service-quadlet.service /home/user/.config/containers/systemd/test-service-quadlet.container Not loaded test-with-pod.container test-with-pod.service /home/user/.config/containers/systemd/test-with-pod.container Not loaded mypod.pod ``` -------------------------------- ### Start and stop pod service with systemctl Source: https://docs.podman.io/en/latest/markdown/podman-generate-systemd.1.html Shows how to start and stop the generated systemd unit for a pod using systemctl --user, and verify with podman pod ps. Note that systemctl defaults to root, so use --user for non-root actions. Ensure shared resources like ports are freed before starting. ```bash $ systemctl --user start pod-systemd-pod.service $ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 0815c7b8e7f5 systemd-pod Running 29 minutes ago 2 6c5d116f4bbe $ sudo podman ps # 0 Number of pods on root. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ systemctl stop pod-systemd-pod.service $ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 272d2813c798 systemd-pod Exited 29 minutes ago 2 6c5d116f4bbe ``` -------------------------------- ### Symlink a templated container instance Source: https://docs.podman.io/en/latest/_sources/markdown/podman-container.unit.5.md.txt Symlink a templated container unit to create an instance. For example, linking foo@.container to foo@bar.container enables starting that instance. ```bash ln -s foo@.container foo@bar.container ``` -------------------------------- ### Generated ExecStart with volume reference Source: https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html Illustrative example of the ExecStart line generated by Quadlet for the referencing example. Shows how the volume name from the template is used in the podman run command. ```ini ExecStart=/usr/bin/podman run ... -v my-name-%i:/mnt/path ... ``` -------------------------------- ### Start with-volume.service and check status for rootless and rootful Source: https://docs.podman.io/en/latest/markdown/podman-quadlet-basic-usage.7.html Commands to copy the with-volume.container file, reload systemd, start the service, and check its status for rootless and rootful configurations. On first start, hello.txt is not yet created; on second start, it appears in the status output. ```bash cp with-volume.container ~/.config/containers/systemd/ systemctl --user daemon-reload systemctl --user start with-volume.service systemctl --user status with-volume.service ``` ```bash sudo cp with-volume.container /etc/containers/systemd/ sudo systemctl daemon-reload sudo systemctl start with-volume.service sudo systemctl status with-volume.service ``` -------------------------------- ### Minimal Quadlet container unit Source: https://docs.podman.io/en/latest/_sources/markdown/podman-container.unit.5.md.txt Minimal Quadlet container unit file with a [Unit], [Container], and [Install] section. Add it with a .container suffix, then enable it with systemctl to start the container. ```ini [Unit] Description=A minimal container [Container] Image=quay.io/centos/centos:latest Exec=sleep 60 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Start mydata-volume.service for rootless and rootful Source: https://docs.podman.io/en/latest/markdown/podman-quadlet-basic-usage.7.html Commands to start the generated mydata-volume.service for rootless and rootful configurations. ```bash systemctl --user start mydata-volume.service ``` ```bash systemctl start mydata-volume.service ```