我创建了一个单元文件,使用以下几行来启动 podman 容器。不幸的是,启动后,journalctl -xe
告诉我服务不需要,正在关闭,服务关闭。podman ps --all
因此exited (0)
,这是一个常规停止。
[Unit]
Description=Service for auto-start the Podman NGINX Container
After=syslog.target
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=podman start nginx
ExecStop=podman stop nginx
[Install]
WantedBy=multi-user.target
我也尝试了一些变体StopWhenUnneeded=false
,但没有什么区别。
系统是RedHat8.官方RedHat 描述解决这个问题没有用。
答案1
有一个 Podman 命令用于创建 systemd 服务单元文件
podman generate systemd --name --new nginx
。
以下是一个例子:
[root@asus ~]# podman create --name nginx -p 80:80 docker.io/library/nginx
7844db33bf66233f71c74ce0d43e590a8478b087198dfc276477baaf20a9b503
[root@asus ~]# podman generate systemd --name --new nginx > /etc/systemd/system/nginx.service
[root@asus ~]# systemctl daemon-reload
[root@asus ~]# systemctl start nginx.service
[root@asus ~]# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@asus ~]# podman --version
podman version 3.4.4
[root@asus ~]# cat /etc/fedora-release
Fedora release 35 (Thirty Five)
[root@asus ~]#