Podman

Podman

Run a container as a systemd service

  • Podman before 4.4

    1. Provision a running container
    podman run -d --name $container_name $image_name
    1. Generate a systemd service unit file for the container
    podman generate systemd --new --name $container_name > "$service_name.service"
    1. Verify and tweak the unit file if needed, and the deploy
    cp "$service_name.service" $HOME/.config/systemd/user
    1. Start and enable the service
      # Verify by running:
    > systemctl --user cat "$service_name.service"
    > systemctl --user start "$service_name.service"   # Verify it runs correctly
    > systemctl --user enable "$service_name.service"  # Auto start at login
  • Podman 4.4+

    1. Create a container unit file

      1.1 Manually

      # $HOME/.config/containers/systemd/$service_name.container
      # The container unit file has an extension of `.container`
      # It also has a dedicated section `Container`
      [Unit]
      Description=$container_description
      After=local-fs.target
       
      # The dedicated container section
      [Container]
      Image=$image
      Exec=$image_start_command
       
      [Install]
      # Start by default on boot
      WantedBy=multi-user.target default.target

      1.2 Using Podlet

      # Install Podlet
      brew install podlet
      # Generate a systemd container unit file
      podlet $podman_command_to_run_a_container
      # e.g. podlet podman run -d --publish 8080:8080 --name $container_name $image_name
    2. Create a systemd service unit file based on the container unit file

      systemctl --user daemon-reload
    3. Check the generated service unit file

      /usr/libexec/podman/quadlet -dryrun -user
    4. Check the service status

      systemctl --user status "$service_name.service"
    5. Start and enable the service

      systemctl --user start "$service_name.service"

Use rootless Podman

Generate Kubernetes YAML based on Podman containers, pods or volumes

Podman will always generate the specification as a Pod.

podman generate kube $container_name

Health Check