podman开机自启

//创建一个容器
[root@localhost ~]#  podman create --name web httpd
e4fe7765fc2a5c7ca3e07adc591c42eb3f9dded238319e49da5212c9eb62fbc6
[root@localhost ~]# podman ps -a
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS      PORTS       NAMES
e4fe7765fc2a  docker.io/library/httpd:latest  httpd-foreground  6 minutes ago  Created                 web


//生成service文件
[root@localhost ~]# podman generate systemd --new --files --name web
/root/container-web.service
[root@localhost ~]# ls
anaconda-ks.cfg  container-web.service


//放入/usr/lib/systemd/system/路径下
[root@localhost ~]# mv container-web.service /usr/lib/systemd/system/
[root@localhost ~]# systemctl doman-reload
Unknown operation doman-reload.
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disable
[root@localhost ~]# setenforce 0

//查看状态
[root@localhost ~]#  systemctl status container-web
● container-web.service - Podman container-web.service
   Loaded: loaded (/usr/lib/systemd/system/container-web.service; disabled; vendor preset: disable>
   Active: inactive (dead)
     Docs: man:podman-generate-systemd(1)
[root@localhost ~]# 

//启动服务
[root@localhost ~]# systemctl enable --now container-web  //设置为开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/container-web.service → /usr/lib/systemd/system/container-web.service.
Created symlink /etc/systemd/system/default.target.wants/container-web.service → /usr/lib/systemd/system/container-web.service.
[root@localhost ~]# systemctl status container-web
● container-web.service - Podman container-web.service
   Loaded: loaded (/usr/lib/systemd/system/container-web.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-05-10 23:36:22 CST; 1min 45s ago
     Docs: man:podman-generate-systemd(1)
  Process: 17154 ExecStartPre=/bin/rm -f /run/container-web.service.ctr-id (code=exited, status=0/>
 Main PID: 17242 (conmon)
    Tasks: 3 (limit: 11216)
   Memory: 3.4M
   CGroup: /system.slice/container-web.service
           ├─17188 /usr/bin/fuse-overlayfs -o metacopy=on,lowerdir=/var/lib/containers/storage/ove>
           └─17242 /usr/bin/conmon --api-version 1 -c a9333cf30ba6e8a89fb5fcd38bb3298e4a54127c2013>

May 10 23:36:21 localhost systemd[1]: Starting Podman container-web.service...
May 10 23:36:21 localhost podman[17156]: e4fe7765fc2a5c7ca3e07adc591c42eb3f9dded238319e49da5212c9e>
May 10 23:36:22 localhost systemd[1]: Started Podman container-web.service.
May 10 23:36:22 localhost podman[17156]: a9333cf30ba6e8a89fb5fcd38bb3298e4a54127c20132d45ee20e902d>
[root@localhost ~]# 

//重新验证
[root@localhost ~]# podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS       NAMES
a9333cf30ba6  docker.io/library/httpd:latest  httpd-foreground  2 minutes ago  Up 2 minutes ago              web
[root@localhost ~]# reboot
[root@localhost ~]# podman ps  //重启后容器自动运行
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS       NAMES
49661a37021c  docker.io/library/httpd:latest  httpd-foreground  6 minutes ago  Up 6 minutes ago              web
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:09:8f:36 brd ff:ff:ff:ff:ff:ff
    inet 192.168.74.129/24 brd 192.168.74.255 scope global dynamic noprefixroute ens160
       valid_lft 1422sec preferred_lft 1422sec
    inet6 fe80::73bc:37d4:4c78:2bee/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: cni-podman0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether ae:88:dd:62:c4:f7 brd ff:ff:ff:ff:ff:ff
    inet 10.88.0.1/16 brd 10.88.255.255 scope global cni-podman0
       valid_lft forever preferred_lft forever
    inet6 fe80::ac88:ddff:fe62:c4f7/64 scope link 
       valid_lft forever preferred_lft forever
4: vethda07a6ee@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master cni-podman0 state UP group default 
    link/ether 16:a0:1b:42:32:82 brd ff:ff:ff:ff:ff:ff link-netns cni-04b21eed-f65a-b7a5-e171-e54411bf9062
    inet6 fe80::14a0:1bff:fe42:3282/64 scope link 
       valid_lft forever preferred_lft forever

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值