Fedora 35
Sponsored Link

Podman : Podman Network2021/11/11

 
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
b5a6ed25b2be  root_default  0.4.0       bridge,portmap,firewall,tuning,dnsname

# 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 fedora /bin/bash -c "dnf -y install iproute; /usr/sbin/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.13
[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

/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
b5a6ed25b2be  root_default  0.4.0       bridge,portmap,firewall,tuning,dnsname

# run a container with specifying [network01]

[root@dlp ~]#
podman run --network network01 fedora /bin/bash -c "dnf -y install iproute; /usr/sbin/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
325e07c81188  srv.world/fedora-httpd:latest  /usr/sbin/httpd -...  19 seconds ago  Up 20 seconds ago  0.0.0.0:8081->80/tcp  happy_elbakyan

[root@dlp ~]#
podman exec 325e07c81188 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.14

# attach network to specify an IP address in the subnet

[root@dlp ~]#
podman network connect network01 325e07c81188
[root@dlp ~]#
podman exec 325e07c81188 ip route

default via 192.168.100.1 dev eth1
default via 10.88.0.1 dev eth0
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.14
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 325e07c81188

[root@dlp ~]#
podman exec 325e07c81188 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.14
[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
b5a6ed25b2be  root_default  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