Ubuntu 22.04
Sponsored Link

Podman : Podman Network2022/04/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

NETWORK ID    NAME        VERSION     PLUGINS
2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning

# display details of [podman]

root@dlp:~#
podman network inspect podman

[
    {
        "cniVersion": "0.4.0",
        "name": "podman",
        "plugins": [
            {
                "bridge": "cni-podman0",
                "hairpinMode": true,
                "ipMasq": true,
                "ipam": {
                    "ranges": [
                        [
                            {
                                "gateway": "10.88.0.1",
                                "subnet": "10.88.0.0/16"
                            }
                        ]
                    ],
                    "routes": [
                        {
                            "dst": "0.0.0.0/0"
                        }
                    ],
                    "type": "host-local"
                },
                "isGateway": true,
                "type": "bridge"
            },
            {
                "capabilities": {
                    "portMappings": true
                },
                "type": "portmap"
            },
            {
                "type": "firewall"
            },
            {
                "type": "tuning"
            }
        ]
    }
]

# [podman] is assigned as container network by default

root@dlp:~#
podman run ubuntu /bin/bash -c "apt-get update; apt-get -y install iproute2; ip route"

.....
.....
default via 10.88.0.1 dev eth0
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.18
[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
root@dlp:~#
podman network ls

NETWORK ID    NAME        VERSION     PLUGINS
2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
5370c5e15abf  network01   0.4.0       bridge,portmap,firewall,tuning,dnsname

# run a container with specifying [network01]

root@dlp:~#
podman run --network network01 ubuntu /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
070c833d948c  srv.world/ubuntu-apache2:latest  /usr/sbin/apachec...  7 seconds ago  Up 7 seconds ago  0.0.0.0:8081->80/tcp  agitated_carver

root@dlp:~#
podman exec 070c833d948c /bin/bash -c "apt-get update; apt-get -y install iproute2; ip route"

.....
.....
default via 10.88.0.1 dev eth0
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.19

# attach network to specify an IP address in the subnet

root@dlp:~#
podman network connect network01 070c833d948c
root@dlp:~#
podman exec 070c833d948c ip route

default via 10.88.0.1 dev eth0
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.19
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 070c833d948c

root@dlp:~#
podman exec 070c833d948c ip route

default via 10.88.0.1 dev eth0
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.19
[3] To remove podman networks, set like follows.
root@dlp:~#
podman network ls

NETWORK ID    NAME        VERSION     PLUGINS
2f259bab93aa  podman      0.4.0       bridge,portmap,firewall,tuning
5370c5e15abf  network01   0.4.0       bridge,portmap,firewall,tuning,dnsname

# 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
Matched Content