Podman : Podman Network2024/03/05 |
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 NETWORK ID NAME DRIVER 2f259bab93aa podman bridge b5a6ed25b2be root_default bridge # display details of [podman] root@dlp:~ # podman network inspect podman [ { "name": "podman", "id": "2f259bab93aaaaa2542ba43ef33eb990d0999ee1b9924b557b7be53c0b7a1bb9", "driver": "bridge", "network_interface": "cni-podman0", "created": "2024-03-05T08:31:05.927897408+09:00", "subnets": [ { "subnet": "10.88.0.0/16", "gateway": "10.88.0.1" } ], "ipv6_enabled": false, "internal": false, "dns_enabled": false, "ipam_options": { "driver": "host-local" } } ]root@dlp:~ # podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/freebsd-nginx latest a0a053cc78a3 5 days ago 1.17 GB localhost/freebsd-httpd latest add46dedb2b7 5 days ago 1.44 GB localhost/freebsd-base latest 2527bfa5eeb4 6 days ago 1.05 GB quay.io/centos/centos stream9 ce3ac91d4020 2 weeks ago 161 MB docker.io/library/ubuntu latest 3db8720ecbf5 2 weeks ago 80.4 MB # [podman] is assigned as container network by default root@dlp:~ # podman run localhost/freebsd-base ifconfig eth0 | grep inet inet 10.88.0.4 netmask 0xffff0000 broadcast 10.88.255.255 |
[2] | If you'd like to assign another network, set like follows. |
# create network [network01] with [192.168.100.0/24] subnet root@dlp:~ # podman network create --subnet 192.168.100.0/24 network01 network01 podman network ls NETWORK ID NAME DRIVER 5370c5e15abf network01 bridge 2f259bab93aa podman bridge b5a6ed25b2be root_default bridge # run a container with specifying [network01] root@dlp:~ # podman run --network network01 localhost/freebsd-base ifconfig eth0 | grep inet inet 192.168.100.2 netmask 0xffffff00 broadcast 192.168.100.255 # to attach the network to existing running container, set like follows root@dlp:~ # podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8e32238083d localhost/freebsd-httpd:latest /usr/local/sbin/h... 7 seconds ago Up 7 seconds 0.0.0.0:8081->80/tcp condescending_hamiltonroot@dlp:~ # podman exec c8e32238083d ifconfig eth0 | grep inet inet 10.88.0.5 netmask 0xffff0000 broadcast 10.88.255.255
root@dlp:~ #
root@dlp:~ # podman network connect network01 c8e32238083d
podman exec c8e32238083d ifconfig | grep -w inet inet 127.0.0.1 netmask 0xffffff00 inet 10.88.0.5 netmask 0xffff0000 broadcast 10.88.255.255 inet 192.168.100.3 netmask 0xffffff00 broadcast 192.168.100.255 # to disconnect the network, set like follows root@dlp:~ # podman network disconnect network01 c8e32238083d root@dlp:~ # podman exec c8e32238083d ifconfig | grep -w inet inet 127.0.0.1 netmask 0xffffff00 inet 10.88.0.5 netmask 0xffff0000 broadcast 10.88.255.255 |
[3] | To remove podman networks, set like follows. |
root@dlp:~ # podman network ls NETWORK ID NAME DRIVER 5370c5e15abf network01 bridge 2f259bab93aa podman bridge b5a6ed25b2be root_default bridge # 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 |