Fix Podman Container Stops After Logout or Reboot

Tested on Red Hat Enterprise Linux 10.2 (Coughlan)
Package podman-5.8.2-5.el10_2.x86_64
Applies to Linux hosts with Podman — rootless logout behavior; reboot survival applies rootful and rootless
Privilege Rootless Podman user for logout tests; [sudo](/sudo-command-in-linux/) for loginctl enable-linger
Scope Why rootless containers stop at SSH logout, loginctl enable-linger and disable-linger, logout versus reboot survival, --restart policies, podman-restart.service, should-start-on-boot filter, Quadlet pointer, and diagnostic commands. Does not cover full rootless setup, every restart-policy option, complete Quadlet tutorial, or container exit-code diagnosis.
Related guides Start, stop, and restart containers
Run containers with podman run
What is Podman?

A detached podman run -d container can look healthy until you log out of SSH or reboot the host. Logout survival and reboot survival are different problems with different fixes. This guide shows how to reproduce each case, which knob applies, and how to confirm your host is configured correctly.

IMPORTANT
This article covers session lifecycle (loginctl enable-linger) and boot restart (--restart, podman-restart.service). It does not diagnose containers that exit immediately with error codes — see container exits immediately when podman ps -a shows Exited right after podman run.

Container stops when the rootless user logs out

Rootless Podman ties container processes to your user systemd session. Start a long-running detached container as a normal user (not root):

bash
podman run -d --name logout-demo registry.access.redhat.com/ubi9/ubi-minimal:latest sleep infinity

Confirm it is running before you disconnect:

bash
podman ps --filter name=logout-demo

Sample output:

output
CONTAINER ID  IMAGE                                               COMMAND         CREATED        STATUS       NAMES
824831da2573  registry.access.redhat.com/ubi9/ubi-minimal:latest  sleep infinity  3 seconds ago  Up 3 seconds logout-demo

Log out of SSH completely — end every interactive session for that user — and log back in. Without linger enabled, list containers again:

bash
podman ps -a --filter name=logout-demo

Sample output after the last session ended:

output
CONTAINER ID  IMAGE                                               COMMAND         CREATED         STATUS                       NAMES
824831da2573  registry.access.redhat.com/ubi9/ubi-minimal:latest  sleep infinity  10 minutes ago  Exited (137) 10 minutes ago  logout-demo

Exited (137) means the process received SIGKILL. systemd tore down user@UID.service when your final session closed, which killed conmon and the container workload. Rootful containers on the system instance do not hit this logout path — this symptom is almost always rootless plus linger disabled.


Why rootless containers can stop at logout

systemd-logind tracks login sessions per user. Rootless Podman stores containers under that user's cgroup tree, managed by user@UID.service.

When linger is off and your last session ends:

  • logind stops the per-user systemd manager for that login period
  • the user's runtime directory under /run/user/UID is removed
  • processes in the user slice — including podman, conmon, and container PID 1 — are terminated

Linger tells logind to keep user@UID.service running even when no one is logged in. That is the upstream-supported way to run rootless daemons that must outlive SSH.


Fix logout survival with loginctl enable-linger

An administrator enables linger for the Podman user. Replace podmantest with your account:

bash
sudo loginctl enable-linger podmantest

When you run the command for your own account from an elevated shell:

bash
sudo loginctl enable-linger "$(id -un)"

enable-linger exits silently on success. Confirm the setting:

bash
loginctl show-user podmantest -p Linger

Sample output:

output
Linger=yes

Start a fresh container with linger active:

bash
podman run -d --name logout-demo2 registry.access.redhat.com/ubi9/ubi-minimal:latest sleep infinity

End your SSH session and reconnect. The container should still be up:

bash
podman ps --filter name=logout-demo2

Sample output:

output
CONTAINER ID  IMAGE                                               COMMAND         CREATED        STATUS       NAMES
4a64dfa9b9d6  registry.access.redhat.com/ubi9/ubi-minimal:latest  sleep infinity  2 minutes ago  Up 2 minutes logout-demo2

Linger keeps the user manager alive; it does not restart a container you already stopped.


Disable linger and what it does not do

Turn linger off when you no longer want background user services after logout:

bash
sudo loginctl disable-linger podmantest

Verify:

bash
loginctl show-user podmantest -p Linger

Sample output:

output
Linger=no

Linger only affects the user systemd session lifecycle. It does not:

  • set a Podman restart policy on any container
  • recreate containers you removed
  • start stopped containers after a host reboot

Treat linger as the logout fix. Reboot survival needs --restart plus podman-restart.service, or a systemd/Quadlet unit.


Logout survival and reboot survival are different

Problem Main mechanism
Process killed at logout loginctl enable-linger keeps user@UID.service running rootless
Process exits while host stays up Podman --restart policy (always, unless-stopped, on-failure)
Start again after host reboot podman-restart.service plus restart policy (should-start-on-boot)
Durable server service Quadlet unit with Restart= and WantedBy=

loginctl enable-linger alone does not restart a manually launched container after reboot. After power loss or reboot, every container process is gone until something explicitly starts it again.


Container is stopped after reboot

No container process survives an OS reboot. Create one without a restart policy to see the default:

bash
podman run -d --name reboot-demo registry.access.redhat.com/ubi9/ubi-minimal:latest sleep infinity

After the host comes back, list all containers:

bash
podman ps -a --filter name=reboot-demo

Sample output:

output
CONTAINER ID  IMAGE                                               COMMAND         CREATED       STATUS                     NAMES
7e8ffee07b78  registry.access.redhat.com/ubi9/ubi-minimal:latest  sleep infinity  2 hours ago   Exited (137) 2 hours ago   reboot-demo

The container record still exists in Podman storage, but the workload is stopped. Something must start it again — you, podman-restart.service, or a systemd unit.


Configure a Podman restart policy

Add --restart=always when you create the container so Podman tracks it for runtime restarts and boot:

bash
podman run -d --name reboot-demo --restart=always registry.access.redhat.com/ubi9/ubi-minimal:latest sleep infinity

Read the stored policy:

bash
podman inspect --format '{{json .HostConfig.RestartPolicy}}' reboot-demo

Sample output:

output
{"Name":"always","MaximumRetryCount":0}

--restart tells Podman what to do when the main process exits while Podman is running on a live host. Boot is a separate step handled by podman-restart.service.


podman-restart.service

Podman ships a systemd unit that starts eligible containers after boot. Inspect the system unit:

bash
systemctl cat podman-restart.service

The ExecStart line on RHEL 10.2 Podman 5.8.2 is:

text
ExecStart=/usr/bin/podman $LOGGING start --all --filter should-start-on-boot=true

Check whether the system service is enabled:

bash
systemctl status podman-restart.service --no-pager

Sample output (truncated):

output
○ podman-restart.service - Podman Start All Containers With Restart Policy Set To Always
     Loaded: loaded (/usr/lib/systemd/system/podman-restart.service; disabled; preset: disabled)
     Active: inactive (dead)

On this lab host the unit exists but is disabled until you enable it. Rootful hosts that rely on CLI-created containers should run:

bash
sudo systemctl enable --now podman-restart.service

Rootless users need linger so user@UID.service runs at boot, then enable the user unit:

bash
systemctl --user enable --now podman-restart.service

Inspect the user unit when present:

bash
systemctl --user cat podman-restart.service

Package layout varies by distribution — verify the unit on your host instead of assuming paths.


always vs unless-stopped after reboot

Both policies can restart a container when its process dies on a running host. They differ after reboot and after manual stop.

Policy Restarts on process exit (host up) Starts after reboot via podman-restart.service
always Yes Yes — while the container exists and was not removed
unless-stopped Yes Only if you had not run podman stop before the reboot

List containers Podman considers boot candidates:

bash
podman ps -a --filter should-start-on-boot=true --format '{{.Names}} {{.Status}}'

With reboot-demo (always) running and unless-demo (unless-stopped) manually stopped:

output
reboot-demo Up 43 seconds

unless-demo does not appear because podman stop recorded an explicit stop. Start it again and the filter includes it:

bash
podman start unless-demo

Re-run the boot filter now that unless-demo is running again:

bash
podman ps -a --filter should-start-on-boot=true --format '{{.Names}} {{.Status}}'

Sample output:

output
reboot-demo Up About a minute
unless-demo Up 2 seconds

After a simulated reboot — user runtime stopped and podman-restart.service started — only reboot-demo came back up; the stopped unless-stopped container stayed exited.


Why --restart is not meaningless

A common misconception is that --restart only matters with Quadlet. That is not accurate.

  • --restart handles process exit while the Podman host is running
  • podman-restart.service handles the after-reboot start for containers in the should-start-on-boot filter

Standalone podman run --restart=always plus an enabled podman-restart.service is a valid pattern for lab boxes and single-container hosts. For production services you usually move to Podman Quadlet and systemd so journalctl, dependency ordering, and systemctl restart apply.


Quadlet is the durable service answer

For a long-running server workload, declare the container in a Quadlet .container file and let systemd own lifecycle:

ini
[Container]
Image=registry.access.redhat.com/ubi9/ubi-minimal:latest
ContainerName=web-demo

[Service]
Restart=always

[Install]
WantedBy=default.target

For this rootless example, default.target starts the service with the user manager. A rootful system Quadlet commonly uses multi-user.target instead.

For rootless Quadlet, place the .container file in the user Quadlet search path, include [Install] WantedBy=default.target, run systemctl --user daemon-reload, and start the generated service with systemctl --user start UNIT.service. Quadlet applies the [Install] section automatically; do not run systemctl --user enable on the generated service. Enable linger when the service must start at boot without anyone logging in.

For rootful Quadlet, use the system Quadlet path, include an appropriate [Install] target such as multi-user.target, run sudo systemctl daemon-reload, and start the generated service with sudo systemctl start UNIT.service.

This article does not walk through Quadlet syntax — see Podman Quadlet and systemd for the full workflow.


Do not combine Podman and systemd restart policy blindly

When systemd generates or manages the unit, systemd should own restart behavior:

ini
[Service]
Restart=always

Do not normally add --restart=always inside the same systemd-managed container definition. One lifecycle manager should decide when the workload restarts. Layering both can produce double restarts or make failures harder to read in logs.


Diagnostic checklist

When a container disappeared or stayed stopped, run these checks in order.

Restart policy on the container:

bash
podman inspect --format '{{json .HostConfig.RestartPolicy}}' CONTAINER

Linger for the rootless user:

bash
loginctl show-user USER -p Linger

System restart service (pick root or user):

bash
systemctl status podman-restart.service

For rootless workloads, check the user-scoped unit the same way:

bash
systemctl --user status podman-restart.service

Boot-eligible containers:

bash
podman ps -a --filter should-start-on-boot=true

Quadlet-managed service:

bash
systemctl status SERVICE

Rootless Quadlet units use the user manager instead:

bash
systemctl --user status SERVICE

Troubleshooting

Symptom Likely cause Fix
Rootless container Exited (137) after SSH logout Linger disabled; user slice torn down sudo loginctl enable-linger USER; recreate or podman start the container
Container stopped after reboot, no restart policy Default policy does not survive boot Recreate with --restart=always or unless-stopped; enable podman-restart.service
always container still stopped after reboot podman-restart.service disabled systemctl enable --now podman-restart.service (root) or user unit with linger
unless-stopped missing after reboot You ran podman stop before reboot podman start CONTAINER; policy skips manually stopped containers
Rootless boot restart never runs Linger off; user manager not active at boot Enable linger, then systemctl --user enable --now podman-restart.service

References


Summary

Rootless Podman containers stop at logout when linger is disabled because they live under user@UID.service, and logind tears that down when your last session ends. sudo loginctl enable-linger USER keeps the user manager running so detached containers can survive SSH disconnect — but linger does not bring containers back after a reboot.

Reboot is a separate problem. Every container process dies when the host restarts; Podman only starts them again when a restart policy marks them for boot (should-start-on-boot) and podman-restart.service runs — or when systemd/Quadlet owns the unit. Use --restart=always when you want boot survival; use unless-stopped when manual podman stop should be remembered across reboot.

For production services, move from ad hoc podman run to Quadlet with Restart= on the unit, enable linger for rootless boot, and avoid stacking Podman --restart on top of systemd-managed containers. When the container exits immediately instead of at logout, read the exit code before changing restart policy — that is a different troubleshooting path.


Frequently Asked Questions

1. Does loginctl enable-linger restart Podman containers after reboot?

No. Linger keeps the per-user systemd manager running after your last login session ends so rootless containers can survive logout. After a host reboot every container process is gone. You need a Podman restart policy such as always plus podman-restart.service, or a systemd Quadlet unit, to start containers again at boot.

2. What is the difference between Podman linger and --restart always?

Linger solves logout survival for rootless users by preventing systemd from tearing down user@UID.service when you disconnect. --restart always tells Podman to restart a container when its main process exits while the host is running, and marks it for podman-restart.service after reboot. They address different problems and are often used together on rootless hosts.

3. Why does my rootless Podman container stop when I close SSH?

Rootless Podman runs under your user systemd session. When linger is disabled and your last interactive session ends, logind stops user@UID.service and the cgroup tree that holds conmon and your container processes. Enable linger with sudo loginctl enable-linger USER so the user manager stays active after logout.

4. Should I use --restart always on a Quadlet-managed container?

Usually no. When systemd or Quadlet owns the unit, set Restart=always or Restart=on-failure on the unit and omit --restart on the container. Two restart managers fighting over the same workload can produce confusing restart loops or masked failures.

5. Why is my unless-stopped container missing after reboot?

unless-stopped is included in the should-start-on-boot filter only while the container is running. If you ran podman stop before the reboot, Podman remembers that manual stop and podman-restart.service skips the container on boot until you podman start it again.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)