普通用户在podman创建容器自启动时必须使用ssh或控制台登录,开始使用根用户ssh登录然后su-切换到普通用户后,就出现了问题
创建podman容器
[shp@localhost ~]$ podman run -dt --name shpweb1 -v /home/shp/shihp:/usr/local/apache2/htdoce:Z httpd
创建目录来存放普通用户的systemd文件
[shp@localhost shihp]$ mkdir ~/.config/systemd/user -p
创建podman容器的systemd文件
[shp@localhost shihp]$ podman generate systemd --files --name shpweb3
/home/shp/shihp/container-shpweb3.service
将podman容器的systemd文件移动到~/.config/systemd/user下
[shp@localhost shihp]$ mv container-shpweb3.service ~/.config/systemd/user
修复selinux的安全上下文、
[shp@localhost shihp]$ restorecon -RvF ~/.config/systemd/user/container-shpweb3.service
开启普通用户system接管权限
[shp@localhost shihp]$ loginctl enable-linger
加载用户的systemd文件
[shp@localhost ~]$ systemctl --user daemon-reload
Failed to connect to bus: No such file or directory
#这里就出现问题,是因为我没有直接使用普通用户ssh登录,这个问题可以两个解决方案
#1.普通用户ssh登录
#2.
[shp@localhost ~]$ loginctl enable-linger shp
[shp@localhost ~]$ export XDG_RUNTIME_DIR=/run/user/$(id -u)
设置下次开机自启动
[shp@localhost ~]$ systemctl --user enable container-shpweb3.service
Created symlink /home/shp/.config/systemd/user/default.target.wants/container-shpweb3.service → /home/shp/.config/systemd/user/container-shpweb3.service.