Podman : Podman Network2021/08/28 |
This is the basic usage to configure Podman Network.
|
|
[1] | When running containers without specifying network, default [podman] network is assigned. |
# display network list root@dlp:~# podman network ls NAME VERSION PLUGINS podman 0.4.0 ptp,portmap,firewall # display details of [podman] root@dlp:~# podman network inspect podman [ { "cniVersion": "0.4.0", "name": "podman", "plugins": [ { "Documentation": "/usr/share/doc/containernetworking-plugins/main_ptp.md", "ipMasq": true, "ipam": { "Documentation": "/usr/share/doc/containernetworking-plugins/ipam_host-local.md", "routes": [ { "dst": "0.0.0.0/0" } ], "subnet": "172.16.16.0/24", "type": "host-local" }, "type": "ptp" }, { "Documentation": "/usr/share/doc/containernetworking-plugins/meta_portmap.md", "capabilities": { "portMappings": true }, "type": "portmap" }, { "Documentation": "/usr/share/doc/containernetworking-plugins/meta_firewall.md", "backend": "iptables", "type": "firewall" } ] } ] # [podman] is assigned as container network by default root@dlp:~# podman run debian /bin/bash -c "apt-get update; apt-get -y install iproute2; ip route" ..... ..... default via 172.16.16.1 dev eth0 172.16.16.0/24 via 172.16.16.1 dev eth0 src 172.16.16.24 172.16.16.1 dev eth0 scope link src 172.16.16.24 |
[2] | If you'd like to assign another network, configure like follows. |
# create network [network01] with [192.168.100.0/24] subnet root@dlp:~# podman network create --subnet 192.168.100.0/24 network01 /etc/cni/net.d/network01.conflist podman network ls NAME VERSION PLUGINS podman 0.4.0 ptp,portmap,firewall network01 0.4.0 bridge,portmap,firewall,tuning # run a container with specifying [network01] root@dlp:~# podman run --network network01 debian /bin/bash -c "apt-get update; apt-get -y install iproute2; ip route" ..... ..... default via 192.168.100.1 dev eth0 192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.2 # to attach the network to existing running container, set like follows下 root@dlp:~# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb7a61a16c5d srv.world/debian-apache2 /usr/sbin/apachec... 4 seconds ago Up 4 seconds ago 0.0.0.0:8081->80/tcp dazzling_kalamroot@dlp:~# podman exec fb7a61a16c5d /bin/bash -c "apt-get update; apt-get -y install iproute2; ip route" ..... ..... default via 172.16.16.1 dev eth0 172.16.16.0/24 via 172.16.16.1 dev eth0 src 172.16.16.25 172.16.16.1 dev eth0 scope link src 172.16.16.25 # attach network to specify an IP address in the subnet root@dlp:~# podman network connect network01 fb7a61a16c5d
podman exec fb7a61a16c5d ip route default via 172.16.16.1 dev eth0 172.16.16.0/24 via 172.16.16.1 dev eth0 src 172.16.16.25 172.16.16.1 dev eth0 scope link src 172.16.16.25 192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.3 # to disconnect the network, set like follows root@dlp:~# podman network disconnect network01 fb7a61a16c5d root@dlp:~# podman exec fb7a61a16c5d ip route default via 172.16.16.1 dev eth0 172.16.16.0/24 via 172.16.16.1 dev eth0 src 172.16.16.25 172.16.16.1 dev eth0 scope link src 172.16.16.25 |
[3] | To remove podman networks, set like follows. |
root@dlp:~# podman network ls NAME VERSION PLUGINS podman 0.4.0 ptp,portmap,firewall network01 0.4.0 bridge,portmap,firewall,tuning # remove [network01] root@dlp:~# podman network rm network01 Error: "network01" has associated containers with it. Use -f to forcibly delete containers and pods: network is being used # force remove containers with [-f] option root@dlp:~# podman network rm -f network01 network01 |
Sponsored Link |