Fedora 34
Sponsored Link

Podman : Podman Network
2021/05/14
 
This is the basic usage to configure Docker 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.3
[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.3

# to attach the network to existing running container, set like follows

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                                     COMMAND    CREATED         STATUS             PORTS   NAMES
01716474c64a  registry.fedoraproject.org/fedora:latest  /bin/bash  17 minutes ago  Up 17 minutes ago          unruffled_bhaskara

[root@dlp ~]#
podman exec 01716474c64a 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.8

# attach network to specify an IP address in the subnet

[root@dlp ~]#
podman network connect network01 01716474c64a
[root@dlp ~]#
podman exec 01716474c64a 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.8
192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.4

# to disconnect the network, set like follows

[root@dlp ~]#
podman network disconnect network01 01716474c64a

[root@dlp ~]#
podman exec 01716474c64a 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.8
[3] To remove docker 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