Rocky_Linux_8
Sponsored Link

Podman : Podman Network2021/07/29

 
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    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 rockylinux /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.8
[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

NAME       VERSION  PLUGINS
podman     0.4.0    bridge,portmap,firewall,tuning
network01  0.4.0    bridge,portmap,firewall,tuning

# run a container with specifying [network01]

[root@dlp ~]#
podman run --network network01 rockylinux /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
dc0c6cfb7fbb  srv.world/rocky-httpd  /bin/bash  15 seconds ago  Up 15 seconds ago          hungry_gauss

[root@dlp ~]#
podman exec dc0c6cfb7fbb 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.10

# attach network to specify an IP address in the subnet

[root@dlp ~]#
podman network connect network01 dc0c6cfb7fbb
[root@dlp ~]#
podman exec dc0c6cfb7fbb 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.10
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 dc0c6cfb7fbb

[root@dlp ~]#
podman exec dc0c6cfb7fbb 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.10
[3] To remove podman networks, set like follows.
[root@dlp ~]#
podman network ls

NAME       VERSION  PLUGINS
podman     0.4.0    bridge,portmap,firewall,tuning
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
Matched Content