Windows 2025
Sponsored Link

Docker : Docker Network2024/12/16

 

This is the basic usage to configure Docker Network.

[1] When running containers without specifying network, default [nat] network is assigned.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# display network list
PS C:\Users\Administrator> docker network ls 
NETWORK ID     NAME                  DRIVER    SCOPE
3e2cfbe7d2ae   docker-file_default   nat       local
f7b77b9d0096   nat                   nat       local
faa4cfb2bcc1   none                  null      local

# display details of [nat]
PS C:\Users\Administrator> docker network inspect nat 
[
    {
        "Name": "nat",
        "Id": "f7b77b9d009642fe5a37c25471015003c17f4f996ce9ecc6afc79cf969bfcb7e",
        "Created": "2024-12-15T17:29:07.3530771-08:00",
        "Scope": "local",
        "Driver": "nat",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "windows",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.22.48.0/20",
                    "Gateway": "172.22.48.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.windowsshim.hnsid": "B213F3B5-1A92-40C0-BF1B-41F04F2ACA08",
            "com.docker.network.windowsshim.networkname": "nat"
        },
        "Labels": {}
    }
]

# [nat] is assigned as container network by default
PS C:\Users\Administrator> docker run mcr.microsoft.com/windows/servercore:ltsc2025 powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::a3be:23c0:1d66:391f%21
   IPv4 Address. . . . . . . . . . . : 172.22.62.224
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.22.48.1
[2] If you'd like to assign another network, set like follows.
# create network [network01] with [192.168.100.0/24] subnet
PS C:\Users\Administrator> docker network create -d "nat" --subnet "192.168.100.0/24" network01 
9f76192ec3e78e476a88e8a3943ef42f1dafa70f1e13ce479ca2a47d3a175500

PS C:\Users\Administrator> docker network ls 
NETWORK ID     NAME                  DRIVER    SCOPE
3e2cfbe7d2ae   docker-file_default   nat       local
f7b77b9d0096   nat                   nat       local
9f76192ec3e7   network01             nat       local
faa4cfb2bcc1   none                  null      local

# run a container with specifying [network01]
PS C:\Users\Administrator> docker run --net network01 mcr.microsoft.com/windows/servercore:ltsc2025 powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::3b3:e67b:7b38:5774%25
   IPv4 Address. . . . . . . . . . . : 192.168.100.15
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

# to attach the network to existing running container, set like follows
PS C:\Users\Administrator> docker ps 
CONTAINER ID   IMAGE           COMMAND   CREATED         STATUS         PORTS                  NAMES
5bf765d9059f   srv.world/iis   "cmd"     8 seconds ago   Up 7 seconds   0.0.0.0:8081->80/tcp   distracted_greider

PS C:\Users\Administrator> docker exec 5bf765d9059f powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2471:c002:6079:fa6b%25
   IPv4 Address. . . . . . . . . . . : 172.22.60.108
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.22.48.1

# attach network to specify an IP address in the subnet
PS C:\Users\Administrator> docker network connect --ip 192.168.100.10 network01 5bf765d9059f 

PS C:\Users\Administrator> docker exec 5bf765d9059f powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2471:c002:6079:fa6b%25
   IPv4 Address. . . . . . . . . . . : 172.22.60.108
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.22.48.1

Ethernet adapter vEthernet (Ethernet) 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::608c:d072:bdf6:4580%29
   IPv4 Address. . . . . . . . . . . : 192.168.100.10
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.100.1

# to disconnect the network, set like follows
PS C:\Users\Administrator> docker network disconnect network01 5bf765d9059f 
PS C:\Users\Administrator> docker exec 5bf765d9059f powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2471:c002:6079:fa6b%25
   IPv4 Address. . . . . . . . . . . : 172.22.60.108
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.22.48.1
[3] To remove docker networks, run like follows.
PS C:\Users\Administrator> docker network ls 
NETWORK ID     NAME                  DRIVER    SCOPE
3e2cfbe7d2ae   docker-file_default   nat       local
f7b77b9d0096   nat                   nat       local
9f76192ec3e7   network01             nat       local
faa4cfb2bcc1   none                  null      local

# remove [network01]
PS C:\Users\Administrator> docker network rm network01 
network01
[4] To connect to Host network, not nat, set like follows.
# confirm network adapter name
PS C:\Users\Administrator> Get-NetAdapter 

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet Instance 0       Red Hat VirtIO Ethernet Adapter               6 Up           52-54-00-65-D1-5C        10 Gbps
vEthernet (nat)           Hyper-V Virtual Ethernet Adapter             12 Up           00-15-5D-F3-C3-AC        10 Gbps
vEthernet (3e2cfbe7d2a... Hyper-V Virtual Ethernet Adapter #2          16 Up           00-15-5D-A8-47-87        10 Gbps
vEthernet (Ethernet)      Hyper-V Virtual Ethernet Container A...      25 Up           00-15-5D-F3-C5-83        10 Gbps

# create [transparent01] network with [transparent] driver
# for [com.docker.network.windowsshim.interface="***"], specify adapter name confirmed above
PS C:\Users\Administrator> docker network create -d transparent -o com.docker.network.windowsshim.interface="Ethernet Instance 0" transparent01 

PS C:\Users\Administrator> docker network ls 
NETWORK ID     NAME                  DRIVER        SCOPE
3e2cfbe7d2ae   docker-file_default   nat           local
f7b77b9d0096   nat                   nat           local
faa4cfb2bcc1   none                  null          local
9a1eeab92372   transparent01         transparent   local

PS C:\Users\Administrator> docker network inspect transparent01 
[
    {
        "Name": "transparent01",
        "Id": "9a1eeab92372e70bfdb60f71a58a36d47ae89c7a4e9969cd29cf78fa50ecef8b",
        "Created": "2024-12-15T19:27:27.5200607-08:00",
        "Scope": "local",
        "Driver": "transparent",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "windows",
            "Options": {},
            "Config": [
                {
                    "Subnet": "0.0.0.0/0"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.windowsshim.hnsid": "8BB0D64F-DFD9-481A-845D-77EFF8F535EB",
            "com.docker.network.windowsshim.interface": "Ethernet Instance 0"
        },
        "Labels": {}
    }
]

PS C:\Users\Administrator> docker images 
REPOSITORY                             TAG        IMAGE ID       CREATED             SIZE
docker-file-web                        latest     9d2d11c741f2   53 minutes ago      5.31GB
srv.world/iis-server                   latest     4e3d76bef20a   About an hour ago   5.26GB
mcr.microsoft.com/windows/servercore   ltsc2025   f9fb7d5c26c9   7 days ago          5.14GB

# run a container with [transparent01] network
PS C:\Users\Administrator> docker run -dt --net transparent01 srv.world/iis-server  
65173d39841167f0791f815389dd174103765f3fc7d482caa1fc5f21dabced3c

PS C:\Users\Administrator> docker ps 
CONTAINER ID   IMAGE                  COMMAND   CREATED          STATUS          PORTS     NAMES
65173d398411   srv.world/iis-server   "cmd"     12 seconds ago   Up 10 seconds   80/tcp    adoring_newton

# display IP address (it is assigned by DHCP server in your local network)
PS C:\Users\Administrator> docker exec 65173d398411 powershell -c "ipconfig" 

Windows IP Configuration


Ethernet adapter vEthernet (Ethernet):

   Connection-specific DNS Suffix  . : srv.world
   Link-local IPv6 Address . . . . . : fe80::d396:9de8:6b69:2d1c%25
   IPv4 Address. . . . . . . . . . . : 10.0.0.232
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.0.0.1

# verify accesses
PS C:\Users\Administrator> curl.exe 10.0.0.232 
Dockerfile test example
Matched Content