podman 普通用户的开机自启

podman 普通用户的开机自启

创建用户
[root@SYL2 ~]# useradd muchen
[root@SYL2 ~]# echo '123456'|passwd --stdin muchen
Changing password for user muchen.
passwd: all authentication tokens updated successfully.

拉取镜像
[root@SYL2 ~]# su - muchen
[muchen@SYL2 ~]$ podman pull httpd
✔ docker.io/library/httpd:latest
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob 214ca5fb9032 done  
Copying blob dc25474c7f97 done  
Copying blob 7cf31a2eeec6 done  
Copying blob c15a4e94ae6b done  
Copying blob bf666e57b9f2 done  
Copying config c58ef9bfbb done  
Writing manifest to image destination
Storing signatures
c58ef9bfbb5789a9882cee610ba778b1368d21b513d6caf32e3075542e13fe81
[muchen@SYL2 ~]$ 

创建目录
[muchen@SYL2 ~]$ mkdir -p .config/systemd/user
[muchen@SYL2 ~]$ podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS       NAMES
ab3401f3eea7  docker.io/library/httpd:latest  httpd-foreground  6 minutes ago  Up 6 minutes ago              web
[muchen@SYL2 ~]$ podman rm -f web
ab3401f3eea7eeb9bc9a530324d7594e4b5226e675fd73f499b739330dc567d0

运行容器
[muchen@SYL2 ~]$ podman run -d --name web docker.io/library/httpd:latest
76ba48a6f0c22445d57ca38c127f5bd7472909251575c1e610abd93b00804f56
[muchen@SYL2 ~]$ cd .config/systemd/user/
[muchen@SYL2 user]$ ls
[muchen@SYL2 user]$ podman generate systemd --files --name web
/home/muchen/.config/systemd/user/container-web.service
[muchen@SYL2 user]$ ls
container-web.service

远程连接
[root@SYL2 ~]# ssh muchen@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:WlI+c2MQDTEJhLAvW//ahd5T4DlwkGIfuB3+u8cWJZY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
muchen@localhost's password: 
Last login: Mon May 23 23:11:24 2022
[muchen@SYL2 ~]$ cd .config/systemd/user/

加载并且设置开机自启
[muchen@SYL2 user]$ systemctl --user daemon-reload
[muchen@SYL2 user]$ systemctl --user enable --now container-web.service 
Created symlink /home/muchen/.config/systemd/user/default.target.wants/container-web.service → /home/muchen/.config/systemd/user/container-web.service.
Job for container-web.service failed because the service did not take the steps required by its unit configuration.
See "systemctl --user status container-web.service" and "journalctl --user -xe" for details.
[muchen@SYL2 user]$ systemctl status container-web.service 
Unit container-web.service could not be found.
[muchen@SYL2 user]$ systemctl --user status container-web.service 
● container-web.service - Podman container-web.service
   Loaded: loaded (/home/muchen/.config/systemd/user/container-web>
   Active: active (running) since Mon 2022-05-23 23:37:03 CST; 22s>
     Docs: man:podman-generate-systemd(1)
  Process: 110867 ExecStopPost=/usr/bin/podman stop -t 10 web (cod>
  Process: 110884 ExecStart=/usr/bin/podman start web (code=exited>
 Main PID: 110907 (conmon)
   CGroup: /user.slice/user-1000.slice/user@1000.service/container>
           ├─110904 /usr/bin/slirp4netns --disable-host-loopback ->
           ├─110907 /usr/bin/conmon --api-version 1 -c 76ba48a6f0c>
           └─76ba48a6f0c22445d57ca38c127f5bd7472909251575c1e610abd>
             ├─110918 httpd -DFOREGROUND
             ├─110929 httpd -DFOREGROUND
             ├─110930 httpd -DFOREGROUND
             └─110931 httpd -DFOREGROUND
[muchen@SYL2 user]$ 

[muchen@SYL2 user]$ podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS             PORTS       NAMES
76ba48a6f0c2  docker.io/library/httpd:latest  httpd-foreground  5 minutes ago  Up 53 seconds ago              web
[muchen@SYL2 user]$ 
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值