--- tags: - Podmancategories: - Containerdate:created: 2023-05-27# updated: 2024-01-19---
Manage Podman Container With Systemd¶
1. Problem IntroductionPodman is different from Docker in that it does not require the docker daemon to control the running of the container in terms of architecture, so the restart of the container needs to be taken over by systemd.¶
2. Generate systemd service file¶
- -t: timeout period- -n: indicates using the container name instead of the container id- -f: indicates generating service files- --new: Delete the old container and start a new container every time it is started
3. Manage Pod with Systemd### (1). Create a Pod```¶
podman pod create --name POD_NAME
### (2). Create Container in Pod```
podman container run --pod POD_NAME --name CONTAINER_NAME1
podman container run --pod POD_NAME --name CONTAINER_NAME2
(3). Generate systemd service files for Pod and Containers inside```¶
podman generate systemd -f --new --name POD_NAME
- -f: indicates generating service files- --new: Delete the old container and start a new container every time it is started- POD_NAME: pod name
## 4. Config Systemd
### (1). Move service file to`/usr/lib/systemd/system`### (2). Restore SELinux Label with command below```
restorecon /usr/lib/systemd/system/container-***.service
(3). Reload daemon with command below```¶
systemctl daemon-reload
REF[1]. https://blog.51cto.com/omaidb/4531846¶
[2]. https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/assembly_porting-containers-to-systemd-using-podman_building-running-and-managing-containers#doc-wrapper
[3]. https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/proc_auto-starting-pods-using-systemd_assembly_porting-containers-to-systemd-using-podman