Configure User Lingering with Podman on Oracle Linux
Introduction
Systemd provides user lingering, enabling user services (such as containers launched with systemd user units) to stay active after the user logs out. Without this, user service managers (and their containers) are stopped on logout.
Objectives
In this tutorial, you'll learn to:
- Use Podman to create and run Pods.
- Use Podman to manage Pods.
- Use Podman to remove Pods.
Prerequisites
Minimum of a single Oracle Linux system
Each system should have Oracle Linux installed and configured with:
- A non-root user account with sudo access
- Access to the Internet
Deploy Oracle Linux
Note: If running in your own tenancy, read the linux-virt-labs
GitHub project README.md and complete the prerequisites before deploying the lab environment.
Open a terminal on the Luna Desktop.
Clone the
linux-virt-labs
GitHub project.git clone https://github.com/oracle-devrel/linux-virt-labs.git
Change into the working directory.
cd linux-virt-labs/ol
Install the required collections.
ansible-galaxy collection install -r requirements.yml
Deploy the lab environment.
ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e use_podman=true -e update_all=true -e os_version="9"
The free lab environment requires the extra variable
local_python_interpreter
, which setsansible_python_interpreter
for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add
-e instance_shape="VM.Standard3.Flex"
or-e os_version="9"
to the deployment command.Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of Oracle Linux is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.
Confirm Podman Works
The container-tools package in Oracle Linux provides the latest versions of Podman, Buildah, Skopeo, and associated dependencies.
Open a terminal and connect via SSH to the ol-node-01 instance.
ssh oracle@<ip_address_of_instance>
Check the version of Podman.
podman -v
Confirm the Podman CLI is working.
podman run quay.io/podman/hello
Example Output:
[oracle@ol-server ~]$ podman run quay.io/podman/hello Trying to pull quay.io/podman/hello:latest... Getting image source signatures Copying blob f82b04e85914 done Copying config dbd85e09a1 done Writing manifest to image destination Storing signatures !... Hello Podman World ...! .--"--. / - - \ / (O) (O) \ ~~~| -=(,Y,)=- | .---. /` \ |~~ ~/ o o \~~~~.----. ~~ | =(X)= |~ / (O (O) \ ~~~~~~~ ~| =(Y_)=- | ~~~~ ~~~| U |~~ Project: https://github.com/containers/podman Website: https://podman.io Documents: https://docs.podman.io Twitter: @Podman_io
Enable Lingering for a User
The username used for this tutorial is oracle
.
Enable lingering for the
oracle
user.sudo loginctl enable-linger oracle
Create a Systemd Unit File for Podman
Create a directory for the systemd unit file.
mkdir -p ~/.config/systemd/user
Create the Systemd unit file.
cat << EOF | tee ~/.config/systemd/user/mycontainer.service > /dev/null [Unit] Description=My Podman Container [Service] Restart=always ExecStart=/usr/bin/podman run --rm --name mycontainer ghcr.io/oracle/oraclelinux9-nginx:1.20 ExecStop=/usr/bin/podman stop -t 10 mycontainer [Install] WantedBy=default.target EOF
Start and enable the Systemd service.
systemctl --user daemon-reload systemctl --user enable --now mycontainer.service
Confirm Systemd Started Podman
Confirm that the service started Podman.
podman ps
Example Output:
[oracle@ol-node-01 ~]$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9ada6b5a635f ghcr.io/oracle/oraclelinux9-nginx:1.20 nginx -g daemon o... 4 minutes ago Up 4 minutes 80/tcp, 443/tcp mycontainer
Check the status of the systemd service.
systemctl --user status mycontainer.service
Example Output:
[oracle@ol-node-01 ~]$ systemctl --user status mycontainer.service ● mycontainer.service - My Podman Container Loaded: loaded (/home/oracle/.config/systemd/user/mycontainer.service; enabled; preset: disabled) Active: active (running) since Wed 2025-09-03 15:18:52 GMT; 1min 4s ago Main PID: 42554 (podman) Tasks: 22 (limit: 201624) Memory: 367.0M CPU: 7.432s CGroup: /user.slice/user-1001.slice/user@1001.service/app.slice/mycontainer.service ├─42554 /usr/bin/podman run --rm --name mycontainer ghcr.io/oracle/oraclelinux9-nginx:1.20 ├─42562 /usr/bin/podman run --rm --name mycontainer ghcr.io/oracle/oraclelinux9-nginx:1.20 ├─42567 catatonit -P ├─42631 /usr/bin/pasta --config-net --dns-forward 169.254.1.1 -t none -u none -T none -U none --no-map-gw --quiet --net> └─42634 /usr/bin/conmon --api-version 1 -c 9ada6b5a635f05242af94d921c045355a02ff1c5c6843b9b77d4797e6cc48947 -u 9ada6b5a> Sep 03 15:18:53 ol-node-01 podman[42562]: Getting image source signatures Sep 03 15:18:53 ol-node-01 podman[42562]: Copying blob sha256:dc9d5c72c83dcb74035f5659842a5bbdb9ceaaab724e942d1fafba3d9a66583d Sep 03 15:18:53 ol-node-01 podman[42562]: Copying blob sha256:768ce871c381eaff86a716a68d16a5fe365a62f4d44ae38e9e8b1ed8fd5bf4bd Sep 03 15:18:57 ol-node-01 podman[42562]: Copying config sha256:86da1899be3dbf9500534c241500247aa0467c76ebbeb2431e42433dcf3e4df2 Sep 03 15:18:57 ol-node-01 podman[42562]: Writing manifest to image destination Sep 03 15:18:58 ol-node-01 podman[42562]: 2025-09-03 15:18:58.037335665 +0000 GMT m=+5.552269770 container create 9ada6b5a635f05242a> Sep 03 15:18:58 ol-node-01 podman[42562]: 2025-09-03 15:18:58.025938165 +0000 GMT m=+5.540872270 image pull 86da1899be3dbf9500534c24> Sep 03 15:18:58 ol-node-01 podman[42562]: 2025-09-03 15:18:58.150895821 +0000 GMT m=+5.665829926 container init 9ada6b5a635f05242af9> Sep 03 15:18:58 ol-node-01 podman[42562]: 2025-09-03 15:18:58.156268852 +0000 GMT m=+5.671202956 container start 9ada6b5a635f05242af>
This confirms that systemd started an Nginx container in Podman. But does it remain active if you log out?
Type
Ctrl-C
to exit the status output.
Confirm the Service Remained Active after Logging Out
Next, you will exit the current session and then reconnect to confirm that the Podman service remains active.
Enter
exit
to leave the current session.Reconnect via SSH to the ol-node-01 instance using the same connection string you used to connect initially.
ssh oracle@<ip_address_of_instance>
Confirm the Podman service is stil active.
podman ps
Check the status of the systemd service.
systemctl --user status mycontainer.service
Next Steps
This tutorial demonstrated how to configure User Lingering with Podman. Enabling lingering allows your Podman containers to run continuously as a user service on Oracle Linux, even after you log out. This approach aligns with modern best practices for rootless container management. Check out the Oracle Linux Training Station for additional tutorials and content.