Fedora 40
Sponsored Link

Podman : Podman Network2024/05/03

 
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
9cae76b64e61  root_default  bridge

# display details of [podman]

[root@dlp ~]#
podman network inspect podman

[
     {
          "name": "podman",
          "id": "2f259bab93aaaaa2542ba43ef33eb990d0999ee1b9924b557b7be53c0b7a1bb9",
          "driver": "bridge",
          "network_interface": "podman0",
          "created": "2024-05-03T17:10:20.447574588+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"
          },
          "containers": {}
     }
]

# [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 proto static metric 100
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.16

[root@dlp ~]#
podman commit $(podman ps -a | tail -1 | awk '{print $1}') srv.world/iproute

[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
[root@dlp ~]#
podman network ls

NETWORK ID    NAME          DRIVER
6d97e767f10f  network01     bridge
2f259bab93aa  podman        bridge
9cae76b64e61  root_default  bridge

# run a container with specifying [network01]

[root@dlp ~]#
podman run --network network01 srv.world/iproute /usr/sbin/ip route

default via 192.168.100.1 dev eth0 proto static metric 100
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
9a596b87f1cf  srv.world/fedora-httpd:latest  /usr/sbin/httpd -...  2 seconds ago  Up 2 seconds  0.0.0.0:8081-->80/tcp  goofy_heisenberg

[root@dlp ~]#
podman exec 9a596b87f1cf /usr/sbin/ip route

default via 10.88.0.1 dev eth0 proto static metric 100
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.17

# attach network to specify an IP address in the subnet

[root@dlp ~]#
podman network connect network01 9a596b87f1cf
[root@dlp ~]#
podman exec 9a596b87f1cf /usr/sbin/ip route

default via 192.168.100.1 dev eth1 proto static metric 100
default via 10.88.0.1 dev eth0 proto static metric 100
10.88.0.0/16 dev eth0 proto kernel scope link src 10.88.0.17
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 9a596b87f1cf

[root@dlp ~]#
podman exec 9a596b87f1cf /usr/sbin/ip route

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

NETWORK ID    NAME          DRIVER
6d97e767f10f  network01     bridge
2f259bab93aa  podman        bridge
9cae76b64e61  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
Matched Content