@@ -172,6 +172,87 @@ You can override the hostname using `--hostname`.
172172When connecting to an existing network using ` docker network connect ` ,
173173you can use the ` --alias ` flag to specify an additional network alias for the container on that network.
174174
175+ ### Subnet allocation
176+
177+ Docker networks can use either explicitly configured subnets or automatically allocated ones from default pools.
178+
179+ #### Explicit subnet configuration
180+
181+ You can specify exact subnets when creating a network:
182+
183+ ``` console
184+ $ docker network create --ipv6 --subnet 192.0.2.0/24 --subnet 2001:db8::/64 mynet
185+ ```
186+
187+ #### Automatic subnet allocation
188+
189+ When no ` --subnet ` option is provided, Docker automatically selects a subnet from predefined "default address pools".
190+ These pools can be configured in ` /etc/docker/daemon.json ` . Docker's built-in default is equivalent to:
191+
192+ ``` json
193+ {
194+ "default-address-pools" : [
195+ {"base" :" 172.17.0.0/16" ,"size" :16 },
196+ {"base" :" 172.18.0.0/16" ,"size" :16 },
197+ {"base" :" 172.19.0.0/16" ,"size" :16 },
198+ {"base" :" 172.20.0.0/14" ,"size" :16 },
199+ {"base" :" 172.24.0.0/14" ,"size" :16 },
200+ {"base" :" 172.28.0.0/14" ,"size" :16 },
201+ {"base" :" 192.168.0.0/16" ,"size" :20 }
202+ ]
203+ }
204+ ```
205+
206+ - ` base ` : The subnet that can be allocated from.
207+ - ` size ` : The prefix length used for each allocated subnet.
208+
209+ When an IPv6 subnet is required and there are no IPv6 addresses in ` default-address-pools ` , Docker allocates
210+ subnets from a Unique Local Address (ULA) prefix. To use specific IPv6 subnets instead, add them to your
211+ ` default-address-pools ` . See [ Dynamic IPv6 subnet allocation] ( ../daemon/ipv6.md#dynamic-ipv6-subnet-allocation )
212+ for more information.
213+
214+ Docker attempts to avoid address prefixes already in use on the host. However, you may need to customize
215+ ` default-address-pools ` to prevent routing conflicts in some network environments.
216+
217+ The default pools use large subnets, which limits the number of networks you can create. You can divide base
218+ subnets into smaller pools to support more networks.
219+
220+ For example, this configuration allows Docker to create 256 networks from ` 172.17.0.0/16 ` .
221+ Docker will allocate subnets ` 172.17.0.0/24 ` , ` 172.17.1.0/24 ` , and so on, up to ` 172.17.255.0/24 ` :
222+
223+ ``` json
224+ {
225+ "default-address-pools" : [
226+ {"base" : " 172.17.0.0/16" , "size" : 24 }
227+ ]
228+ }
229+ ```
230+
231+ You can also request a subnet with a specific prefix length from the default pools by using unspecified
232+ addresses in the ` --subnet ` option:
233+
234+ ``` console
235+ $ docker network create --ipv6 --subnet ::/56 --subnet 0.0.0.0/24 mynet
236+ 6686a6746b17228f5052528113ddad0e6d68e2e3905d648e336b33409f2d3b64
237+ $ docker network inspect mynet -f ' {{json .IPAM.Config}}' | jq .
238+ [
239+ {
240+ "Subnet": "172.19.0.0/24",
241+ "Gateway": "172.19.0.1"
242+ },
243+ {
244+ "Subnet": "fdd3:6f80:972c::/56",
245+ "Gateway": "fdd3:6f80:972c::1"
246+ }
247+ ]
248+ ```
249+
250+ > [ !NOTE]
251+ >
252+ > Support for unspecified addresses in ` --subnet ` was introduced in Docker 29.0.0.
253+ > If Docker is downgraded to an older version, networks created in this way will become unusable.
254+ > They can be removed and re-created, or will function again if the daemon is restored to 29.0.0 or later.
255+
175256## DNS services
176257
177258Containers use the same DNS servers as the host by default, but you can
0 commit comments