CentOS Stream 10

Docker : Docker Network2025/08/08

 

This is the basic usage to configure Docker Network.

[1] When running containers without specifying network, default [bridge] network is assigned.
# display network list

[root@dlp ~]#
docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
b2b49215e21c   bridge         bridge    local
46a22149dcdd   host           host      local
dd1de075129c   none           null      local
2b65fd497827   root_default   bridge    local

# display details of [bridge]

[root@dlp ~]#
docker network inspect bridge

[
    {
        "Name": "bridge",
        "Id": "b2b49215e21cbf4f2f8c5662d60af86194000c724c19666a6b99dec9af788fd1",
        "Created": "2025-08-08T15:09:41.61267+09:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv4": true,
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

# [bridge] is assigned as container network by default

[root@dlp ~]#
docker run quay.io/centos/centos:stream10 /bin/bash -c "dnf -y install iproute; /usr/sbin/ip route" -name centos-iproute

.....
.....
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2

[root@dlp ~]#
docker ps -a | head -2

CONTAINER ID   IMAGE                            COMMAND                  CREATED             STATUS                           PORTS     NAMES
634a3c701e35   quay.io/centos/centos:stream10   "/bin/bash -c 'dnf -..."   33 seconds ago      Exited (0) 25 seconds ago                  funny_tu
[root@dlp ~]#
docker commit 634a3c701e35 srv.world/centos-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 ~]#
docker network create --subnet 192.168.100.0/24 network01

2cad953742ab734956e767cfc9f5bdd3e0b77c40a5396429447d4a8e43da6280

[root@dlp ~]#
docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
b2b49215e21c   bridge         bridge    local
46a22149dcdd   host           host      local
2cad953742ab   network01      bridge    local
dd1de075129c   none           null      local
2b65fd497827   root_default   bridge    local

# run a container with specifying [network01]

[root@dlp ~]#
docker run --net network01 srv.world/centos-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 ~]#
docker ps

CONTAINER ID   IMAGE                      COMMAND       CREATED         STATUS         PORTS     NAMES
89454c55675e   srv.world/centos-iproute   "/bin/bash"   6 seconds ago   Up 6 seconds             jovial_pare

[root@dlp ~]#
docker exec acfcd97f01d2 ip route

default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2

# attach network to specify an IP address in the subnet

[root@dlp ~]#
docker network connect --ip 192.168.100.10 network01 89454c55675e
[root@dlp ~]#
docker exec 89454c55675e ip route

default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2
192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10

# to disconnect the network, set like follows

[root@dlp ~]#
docker network disconnect network01 89454c55675e

[root@dlp ~]#
docker exec 89454c55675e ip route

default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2
[3] To remove docker networks, set like follows.
[root@dlp ~]#
docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
b2b49215e21c   bridge         bridge    local
46a22149dcdd   host           host      local
2cad953742ab   network01      bridge    local
dd1de075129c   none           null      local
2b65fd497827   root_default   bridge    local

# remove [network01]

[root@dlp ~]#
docker network rm network01

network01
[root@dlp ~]#
docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
b2b49215e21c   bridge         bridge    local
46a22149dcdd   host           host      local
dd1de075129c   none           null      local
2b65fd497827   root_default   bridge    local
[4] To connect to Host network, set like follows.
[root@dlp ~]#
docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
b2b49215e21c   bridge         bridge    local
46a22149dcdd   host           host      local
dd1de075129c   none           null      local
2b65fd497827   root_default   bridge    local

[root@dlp ~]#
docker images

REPOSITORY                 TAG        IMAGE ID       CREATED             SIZE
srv.world/centos-iproute   latest     8b9c021f5d90   12 minutes ago      344MB
root-web                   latest     5bc6e8e3f1a9   42 minutes ago      345MB
srv.world/centos-httpd     latest     134889cd315b   About an hour ago   351MB
srv.world/centos-nginx     latest     b587aa926cbf   About an hour ago   345MB
quay.io/centos/centos      stream10   02ae49ff109e   7 weeks ago         306MB

# run a container with [host] network

[root@dlp ~]#
docker run -d --net host srv.world/centos-httpd

670d8df3d4e23febcf18a78da60a38282dd9332a838a29ee040d8ab369d0f60a

[root@dlp ~]#
docker ps

CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS     NAMES
670d8df3d4e2   srv.world/centos-httpd   "/usr/sbin/httpd -D ..."   12 seconds ago   Up 11 seconds             nice_villani

# the port [httpd] service listens on container is used on Host network

[root@dlp ~]#
ss -napt | grep 80

LISTEN 0      511                *:80              *:*    users:(("httpd",pid=8874,fd=4),("httpd",pid=8856,fd=4),("httpd",pid=8855,fd=4),("httpd",pid=8841,fd=4))

[root@dlp ~]#
curl localhost

Index.html on Aapche httpd
Matched Content