CMD cd /opt/blog && hexo clean && hexo g && hexo server EOF
[root@podman ~]# podman build -f Podmanfile -t hexo:v1 [root@podman ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/hexo v1 5a535420cf24 6 minutes ago 962 MB
容器网络
端口暴露
# 端口暴露 [root@podman ~]# podman run -itd --name busybox-test -p80 busybox b02b05b1881f8aa0cbca93f905a6559729e0a5c0e3be69adae2877d146579143 [root@podman ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b02b05b1881f docker.io/library/busybox:latest sh 5 seconds ago Up 6 seconds 0. 0. 0. 0:38171->80/tcp busybox-test [root@podman ~]# podman exec -it b02 /bin/sh / # cd /var/ /var # ls spool www /var # httpd -h www /var # netstat -tlnp Active Internet connections ( only servers ) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 :::80 :::* LISTEN 5/httpd # 端口映射,把容器的端口映射为宿主机的一个特定或者随机端口,使得外部用户可以访问服务器内部服务,其原理是在容器底层做了iptables的地址转发,转出的流量做SNAT源地址转发,转入的流量做DNAT目标地址转发。 # 指定端口转发 [root@podman ~]# podman run -itd --name myipaddr -p 80:80 traefik/whoami bbcc67b5fb1ce98b51335755c13498e87ace3da420b5a430001738cb27768e28 [root@podman ~]# curl 127. 0. 0. 1 Hostname: bbcc67b5fb1c IP: 127. 0. 0. 1 IP: ::1 IP: 10. 88. 0. 5 IP: fe80::c79:daff:fe48:4cb8 RemoteAddr: 10. 88. 0. 1:55560 GET / HTTP/1. 1 Host: 127. 0. 0. 1 User-Agent: curl/8. 6. 0 Accept: */*
网络架构
Podman的网络架构有4种模式:
桥接模式(默认)
non模式(仅本地回环)
# 桥接模式(默认) [root@podman ~]# podman inspect myipaddr |grep IPAdd* "IPAddress": "10. 88. 0. 5", "IPAddress": "10. 88. 0. 5", # none模式(仅本地回环) [root@podman ~]# podman run -d --name=network-none --net=none nginx 539143ba161c73617ac1fd15e74a599753a71ce9658326bc5b8ebacaae114b86 [root@podman ~]# podman inspect 539143 |grep IPAdd* "IPAddress": "", "IPAddress": "", # host模式,容器使用当前主机IP root@podman ~]# podman run --network=host nginx /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2025/01/18 16:47:15 [notice] 1#1: using the "epoll" event method 2025/01/18 16:47:15 [notice] 1#1: nginx/1. 27. 3 2025/01/18 16:47:15 [notice] 1#1: built by gcc 12. 2. 0 ( Debian 12. 2. 0-14 ) 2025/01/18 16:47:15 [notice] 1#1: OS: Linux 6. 12. 9-100. fc40. x86_64 2025/01/18 16:47:15 [notice] 1#1: getrlimit( RLIMIT_NOFILE ): 1048576:1048576 2025/01/18 16:47:15 [notice] 1#1: start worker processes 2025/01/18 16:47:15 [notice] 1#1: start worker process 24 127. 0. 0. 1 - - [18/Jan/2025:16:47:22 +0000] "GET / HTTP/1. 1" 200 615 "-" "curl/8. 6. 0" "-" # container:<id>模式,容器之间共享Network Namespace,荣期间进程通过lo网卡通信 [root@podman ~]# podman run -itd --name bb busybox 365cf25286131e596f3aef54c43fed1b83e5be5ecc5f18e4de98242812f4002d [root@podman ~]# podman run -d --name nginx --network=container:bb nginx 1287874746dcc6f72158b8fdb1ddf07ba13bdda06bd5a04bfdecaf86426fb927 [root@podman ~]# podman exec -it bb /bin/sh [root@podman ~]# curl 10. 88. 0. 7 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
网络实现
# 查看网络模式,可以看到名为podman的网桥 [root@podman ~]# podman network ls NETWORK ID NAME DRIVER 2f259bab93aa podman bridge # 查看podman网桥信息 [root@podman ~]# ip a …… 5: podman0: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether ca:2c:2d:8d:b8:21 brd ff:ff:ff:ff:ff:ff inet 10. 88. 0. 1/16 brd 10. 88. 255. 255 scope global podman0 valid_lft forever preferred_lft forever inet6 fe80::c82c:2dff:fe8d:b821/64 scope link proto kernel_ll valid_lft forever preferred_lft forever 6: veth0@if2: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc noqueue master podman0 state UP group default qlen 1000 link/ether fa:55:23:21:f6:c3 brd ff:ff:ff:ff:ff:ff link-netns netns-0e73c46a-0951-048b-fbc8-5e25f3d52e72 inet6 fe80::18b5:62ff:fec9:3476/64 scope link proto kernel_ll valid_lft forever preferred_lft forever # 查看NAT规则 [root@podman ~]# iptables -L -t nat