podman普通用户容器的开机自启

  • podman 用户设置容器开机自启

先创建个用户设置密码

拉取镜像

[qzl@localhost ~]$ podman pull nginx
Resolving "nginx" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob 589b7251471a done  
Copying blob b4df32aa5a72 done  
Copying blob a9edb18cadd1 done  
Copying blob a2abf6c4d29d done  
Copying blob a0bcbecc962e done  
Copying blob 186b1aaa4aa6 done  
Copying config 605c77e624 done  
Writing manifest to image destination
Storing signatures
605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85
[qzl@localhost ~]$ podman images
REPOSITORY               TAG         IMAGE ID      CREATED       SIZE
docker.io/library/nginx  latest      605c77e624dd  4 months ago  146 MB

启动容器

[qzl@localhost ~]$ podman run -d --name nginx1  docker.io/library/nginx:latest 
982dd9e04ed6b35b0a03da43572b964cf2808e709f24ff1c0030d783d66ec319
[qzl@localhost ~]$ podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS            PORTS       NAMES
982dd9e04ed6  docker.io/library/nginx:latest  nginx -g daemon o...  7 seconds ago  Up 7 seconds ago              nginx1

生成配置文件

[qzl@localhost ~]$ mkdir -p .config/systemd/sb
[qzl@localhost ~]$  cd .config/systemd/sb/
[qzl@localhost sb]$ podman generate  systemd --files --name nginx
Error: nginx does not refer to a container or pod: no pod with name or ID nginx found: no such pod: no container with name or ID "nginx" found: no such container
[qzl@localhost sb]$ podman generate  systemd --files --name nginx1
/home/qzl/.config/systemd/sb/container-nginx1.service
[qzl@localhost sb]$ cat container-nginx.service 
cat: container-nginx.service: 没有那个文件或目录
[qzl@localhost sb]$ cat container-nginx1.service
# container-nginx1.service
# autogenerated by Podman 4.0.2
# Sun May 15 10:10:14 EDT 2022

[Unit]
Description=Podman container-nginx1.service
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target

远程连接用户

[root@localhost ~]# ssh qzl@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:4k3Xw2Wq78GjEDbAJyNZOri0sZHwO8nvISMqanvR994.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
qzl@localhost's password: 
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun May 15 10:05:12 2022

设置开机自启动

[qzl@localhost sb]$ systemctl --user enable --now container-nginx1.service
Created symlink /home/shuaige/.config/systemd/user/multi-user.target.wants/container-nginx.service → /home/shuaige/.config/systemd/sb/container-nginx.service.
Created symlink /home/shuaige/.config/systemd/user/default.target.wants/container-nginx.service → /home/shuaige/.config/systemd/sb/container-nginx.service.
[shuaige@localhost sb]$ systemctl --user status container-nginx.service
● container-nginx.service - Podman container-nginx.service
   Loaded: loaded (/home/shuaige/.config/systemd/sb/container-nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-12-15 07:25:24 EST; 3min 24s ago
     Docs: man:podman-generate-systemd(1)
 Main PID: 7978 (conmon)
   CGroup: /user.slice/user-1000.slice/user@1000.service/container-nginx.service
           ├─7972 /usr/bin/slirp4netns --disable-host-loopback --mtu=65520 --enable-sandbox --enable-seccomp -c -e 3 -r 4 --netns>
           ├─7975 /usr/bin/fuse-overlayfs -o ,lowerdir=/home/shuaige/.local/share/containers/storage/overlay/l/UBB5BCEQLHQ2G7RFOR>
           ├─7978 /usr/bin/conmon --api-version 1 -c 7ed9063a90a9c3b48096ee8fcec60e799c6103fb8fe8ae9226bf8e7d5eee1591 -u 7ed9063a>
           ├─7981 nginx: master process nginx -g daemon off;
           └─8000 nginx: worker process
lines 1-11/11 (END)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值