Skip to content

Commit a8d2c50

Browse files
committed
Describe default-address-pools, and --subnet prefix-len option
Signed-off-by: Rob Murray <[email protected]>
1 parent 14acf49 commit a8d2c50

File tree

2 files changed

+92
-26
lines changed

2 files changed

+92
-26
lines changed

content/manuals/engine/daemon/ipv6.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,42 +126,24 @@ will be used when IPv6 is enabled. These `/64` subnets include a 40-bit
126126
Global ID based on the Docker Engine's randomly generated ID, to give a
127127
high probability of uniqueness.
128128

129+
The built-in default address pool configuration is shown in [Subnet allocation](../network/_index.md#subnet-allocation).
130+
It does not include any IPv6 pools.
131+
129132
To use different pools of IPv6 subnets for dynamic address allocation,
130133
you must manually configure address pools of the daemon to include:
131134

132135
- The default IPv4 address pools
133136
- One or more IPv6 pools of your own
134137

135-
The default address pool configuration is:
136-
137-
```json
138-
{
139-
"default-address-pools": [
140-
{ "base": "172.17.0.0/16", "size": 16 },
141-
{ "base": "172.18.0.0/16", "size": 16 },
142-
{ "base": "172.19.0.0/16", "size": 16 },
143-
{ "base": "172.20.0.0/14", "size": 16 },
144-
{ "base": "172.24.0.0/14", "size": 16 },
145-
{ "base": "172.28.0.0/14", "size": 16 },
146-
{ "base": "192.168.0.0/16", "size": 20 }
147-
]
148-
}
149-
```
150-
151-
The following example shows a valid configuration with the default values and
152-
an IPv6 pool. The IPv6 pool in the example provides up to 256 IPv6 subnets of
153-
size `/64`, from an IPv6 pool of prefix length `/56`.
138+
The following example shows a valid configuration with IPv4 and IPv6 pools,
139+
both pools provide 256 subnets. IPv4 subnets with prefix length `/24` will
140+
be allocated from a `/16` pool. IPv6 subnets with prefix length `/64` will
141+
be allocated from a `/56` pool.
154142

155143
```json
156144
{
157145
"default-address-pools": [
158-
{ "base": "172.17.0.0/16", "size": 16 },
159-
{ "base": "172.18.0.0/16", "size": 16 },
160-
{ "base": "172.19.0.0/16", "size": 16 },
161-
{ "base": "172.20.0.0/14", "size": 16 },
162-
{ "base": "172.24.0.0/14", "size": 16 },
163-
{ "base": "172.28.0.0/14", "size": 16 },
164-
{ "base": "192.168.0.0/16", "size": 20 },
146+
{ "base": "172.17.0.0/16", "size": 24 },
165147
{ "base": "2001:db8::/56", "size": 64 }
166148
]
167149
}
@@ -176,6 +158,9 @@ size `/64`, from an IPv6 pool of prefix length `/56`.
176158
> The default IPv4 pools are from the private address range,
177159
> similar to the default IPv6 [ULA][wikipedia-ipv6-ula] networks.
178160

161+
See [Subnet allocation](../network/_index.md#subnet-allocation) for more information about
162+
`default-address-pools`.
163+
179164
[wikipedia-ipv6-reserved]: https://en.wikipedia.org/wiki/Reserved_IP_addresses#IPv6
180165
[wikipedia-ipv6-ula]: https://en.wikipedia.org/wiki/Unique_local_address
181166

content/manuals/engine/network/_index.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,87 @@ You can override the hostname using `--hostname`.
172172
When connecting to an existing network using `docker network connect`,
173173
you 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

177258
Containers use the same DNS servers as the host by default, but you can

0 commit comments

Comments
 (0)