docker-podman管理容器

podman 管理容器
范例:podman管理容器

安装httpd

#安装httpd
[root@centos8 ~]#podman pull httpd
[root@centos8 ~]#podman run -d --name web -p 80:80 httpd
[root@centos8 ~]#curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>
[root@centos8 ~]#podman exec -it web /bin/sh
# ls    
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  modules
# cd htdocs        
# cat index.html
<html><body><h1>It works!</h1></body></html>
# echo welcome to magedu > index.html
# exit
[root@centos8 ~]#curl 127.0.0.1
welcome to magedu
​
#安装nginx
[root@centos8 ~]#podman run -dt -p 80:80 --name nginx -v /data:/data -e NGINX_VERSION=1.16 nginx:1.16.0
[root@centos8 ~]#podman stop nginx
​
#将容器设为开机启动
[root@centos8 ~]#vim  /lib/systemd/system/nginx_podman.service 
[root@centos8 ~]#cat   /lib/systemd/system/nginx_podman.service 
[Unit]
Description=Podman Nginx Service
After=network.target
After=network-online.target
​
[Service]
Type=simple
ExecStart=/usr/bin/podman start -a nginx
ExecStop=/usr/bin/podman stop -t 10 nginx
Restart=always
​
[Install]
WantedBy=multi-user.target
​
[root@centos8 ~]#systemctl daemon-reload 
[root@centos8 ~]#systemctl enable --now nginx_podman.service 
[root@centos8 ~]#curl 127.0.0.1
​
#podman 查看日志
[root@centos8 ~]#podman logs   nginx
10.0.0.8 - - [24/Feb/2020:14:19:45 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.61.1" "-"
10.0.0.1 - - [24/Feb/2020:14:25:54 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" "-"
[root@centos8 ~]#podman  port nginx
80/tcp -> 0.0.0.0:80
​
[root@centos8 ~]#ss -ntl
State        Recv-Q        Send-Q   Local Address:Port    Peer Address:Port        
LISTEN       0             128            0.0.0.0:80           0.0.0.0:*           
LISTEN       0             128            0.0.0.0:22           0.0.0.0:*           
LISTEN       0             128               [::]:22              [::]:*              
[root@centos8 ~]#systemctl stop nginx_podman.service 
[root@centos8 ~]#ss -ntl
State        Recv-Q        Send-Q     Local Address:Port     Peer Address:Port        
LISTEN       0             128              0.0.0.0:22            0.0.0.0:*           
LISTEN       0             128                 [::]:22               [::]:* 
​
#查看进程信息
[root@centos8 ~]#systemctl start nginx_podman.service 
[root@centos8 ~]#pstree -p
systemd(1)─┬─NetworkManager(664)─┬─{NetworkManager}(698)
           │                     └─{NetworkManager}(699)
           ├─VGAuthService(659)
           ├─agetty(766)
           ├─atd(763)
           ├─auditd(626)───{auditd}(627)
           ├─automount(789)─┬─{automount}(796)
           │                ├─{automount}(797)
           │                ├─{automount}(805)
           │                └─{automount}(822)
           ├─conmon(2378)─┬─nginx(2388)───nginx(2401)
           │              └─{conmon}(2380)
           ├─crond(762)
           ├─dbus-daemon(661)
           ├─podman(2308)─┬─{podman}(2309)
           │              ├─{podman}(2310)
           │              ├─{podman}(2311)
           │              ├─{podman}(2312)
           │              ├─{podman}(2313)
           │              ├─{podman}(2316)
           │              ├─{podman}(2321)
           │              ├─{podman}(2326)
           │              └─{podman}(2399)
           ├─polkitd(668)─┬─{polkitd}(697)
           │              ├─{polkitd}(700)
           │              ├─{polkitd}(703)
           │              ├─{polkitd}(704)
           │              └─{polkitd}(754)
           ├─rngd(667)───{rngd}(677)
           ├─rsyslogd(788)─┬─{rsyslogd}(795)
           │               └─{rsyslogd}(798)
           ├─sshd(711)─┬─sshd(1361)───sshd(1375)───bash(1377)
           │           └─sshd(1362)───sshd(1376)───bash(1380)───pstree(2504)
           ├─sssd(658)─┬─sssd_be(730)
           │           └─sssd_nss(758)
           ├─systemd(1366)───(sd-pam)(1369)
           ├─systemd-journal(553)
           ├─systemd-logind(760)
           ├─systemd-udevd(586)
           ├─tuned(702)─┬─{tuned}(1073)
           │            ├─{tuned}(1076)
           │            └─{tuned}(1088)
           └─vmtoolsd(660)
​
#nginx进程杀死后还会自动启动
[root@centos8 ~]#kill 2388
[root@centos8 ~]#ps aux|grep nginx
root       2939  1.1  8.4 908244 69240 ?        Ssl  22:45   0:00 /usr/bin/podman start -a nginx
root       3009  0.0  0.3 142832  2652 ?        Ssl  22:45   0:00 /usr/libexec/podman/conmon -s -c 9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823 -u 9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823 -n nginx -r /usr/bin/runc -b /var/lib/containers/storage/overlay-containers/9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823/userdata -p /var/run/containers/storage/overlay-containers/9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823/userdata/pidfile --exit-dir /var/run/libpod/exits --exit-command /usr/bin/podman --exit-command-arg --root --exit-command-arg /var/lib/containers/storage --exit-command-arg --runroot --exit-command-arg /var/run/containers/storage --exit-command-arg --log-level --exit-command-arg error --exit-command-arg --cgroup-manager --exit-command-arg systemd --exit-command-arg --tmpdir --exit-command-arg /var/run/libpod --exit-command-arg --runtime --exit-command-arg runc --exit-command-arg --storage-driver --exit-command-arg overlay --exit-command-arg --events-backend --exit-command-arg journald --exit-command-arg container --exit-command-arg cleanup --exit-command-arg 9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823 --socket-dir-path /var/run/libpod/socket -t -l k8s-file:/var/lib/containers/storage/overlay-containers/9198c59a8a3db50801c52ceaa39521b4381ac46ab7c16907130244d2a328e823/userdata/ctr.log --log-level error
root       3019  2.5  0.6  32656  5364 pts/0    Ss+  22:45   0:00 nginx: master process nginx -g daemon off;
101        3031  0.0  0.3  33144  2636 pts/0    S+   22:45   0:00 nginx: worker process
root       3034  0.0  0.1  12108  1072 pts/1    S+   22:45   0:00 grep --color=auto nginx
​
​
[root@centos8 ~]#podman top nginx
USER    PID   PPID   %CPU    ELAPSED           TTY     TIME   COMMAND
root    1     0      0.000   4m38.979412738s   pts/0   0s     nginx: master process nginx -g daemon off; 
nginx   6     1      0.000   4m37.979473913s   pts/0   0s     nginx: worker process 
[root@centos8 ~]#podman stats nginx
ID             NAME    CPU %   MEM USAGE / LIMIT   MEM %   NET IO         BLOCK IO   PIDS
9198c59a8a3d   nginx   --      2.474MB / 835.8MB   0.30%   2.25kB / 1.742kB  -- / --    2

本文链接:http://www.yunweipai.com/34812.html

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/52656.html

(0)
上一篇 2021年8月6日
下一篇 2021年8月6日

相关推荐

发表回复

登录后才能评论