@@ -32,17 +32,22 @@ following custom `iptables` chains:
32
32
33
33
* ` DOCKER-USER `
34
34
* A placeholder for user-defined rules that will be processed before rules
35
- in the ` DOCKER ` chain.
35
+ in the ` DOCKER-FORWARD ` and ` DOCKER ` chains.
36
+ * ` DOCKER-FORWARD `
37
+ * The first stage of processing for Docker's networks. Rules that pass packets
38
+ that are not related to established connections to the other Docker chains,
39
+ as well as rules to accept packets that are part of established connections.
36
40
* ` DOCKER `
37
41
* Rules that determine whether a packet that is not part of an established
38
42
connection should be accepted, based on the port forwarding configuration
39
43
of running containers.
40
44
* ` DOCKER-ISOLATION-STAGE-1 ` and ` DOCKER-ISOLATION-STAGE-2 `
41
45
* Rules to isolate Docker networks from each other.
46
+ * ` DOCKER-INGRESS `
47
+ * Rules related to Swarm networking.
42
48
43
- In the ` FORWARD ` chain, Docker adds rules that pass packets that are not related
44
- to established connections to these custom chains, as well as rules to accept
45
- packets that are part of established connections.
49
+ In the ` FORWARD ` chain, Docker adds rules that unconditionally jump to the
50
+ ` DOCKER-USER ` , ` DOCKER-FORWARD ` and ` DOCKER-INGRESS ` chains.
46
51
47
52
In the ` nat ` table, Docker creates chain ` DOCKER ` and adds rules to implement
48
53
masquerading and port-mapping.
@@ -53,6 +58,8 @@ Packets that get accepted or rejected by rules in these custom chains will not
53
58
be seen by user-defined rules appended to the ` FORWARD ` chain. So, to add
54
59
additional rules to filter these packets, use the ` DOCKER-USER ` chain.
55
60
61
+ Rules appended to the ` FORWARD ` chain will be processed after Docker's rules.
62
+
56
63
### Match the original IP and ports for requests
57
64
58
65
When packets arrive to the ` DOCKER-USER ` chain, they have already passed through
@@ -261,9 +268,9 @@ configure the daemon to use the loopback address (`127.0.0.1`) instead.
261
268
262
269
> [ !WARNING]
263
270
>
264
- > Hosts within the same L2 segment (for example, hosts connected to the same
265
- > network switch) can reach ports published to localhost.
266
- > For more information, see
271
+ > In releases older than 28.0.0, hosts within the same L2 segment (for example,
272
+ > hosts connected to the same network switch) can reach ports published to
273
+ > localhost. For more information, see
267
274
> [ moby/moby #45610 ] ( https://github.com/moby/moby/issues/45610 )
268
275
269
276
To configure this setting for user-defined bridge networks, use
@@ -301,16 +308,36 @@ Alternatively, you can use the `dockerd --ip` flag when starting the daemon.
301
308
302
309
## Docker on a router
303
310
304
- Docker sets the policy for the ` FORWARD ` chain to ` DROP ` . This will prevent
305
- your Docker host from acting as a router.
311
+ On Linux, Docker needs "IP Forwarding" enabled on the host. So, it enables
312
+ the ` sysctl ` settings ` net.ipv4.ip_forward ` and ` net.ipv6.conf.all.forwarding `
313
+ it they are not already enabled when it starts. When it does that, it also
314
+ sets the policy of the iptables ` FORWARD ` chain to ` DROP ` .
315
+
316
+ If Docker sets the policy for the ` FORWARD ` chain to ` DROP ` . This will prevent
317
+ your Docker host from acting as a router, it is the recommended setting when
318
+ IP Forwarding is enabled.
306
319
307
- If you want your system to function as a router, you must add explicit
308
- ` ACCEPT ` rules to the ` DOCKER-USER ` chain. For example:
320
+ To stop Docker from setting the ` FORWARD ` chain's policy to ` DROP ` , include
321
+ ` "ip-forward-no-drop": true ` in ` /etc/docker/daemon.json ` , or add option
322
+ ` --ip-forward-no-drop ` to the ` dockerd ` command line.
323
+
324
+ Alternatively, you may add ` ACCEPT ` rules to the ` DOCKER-USER ` chain for the
325
+ packets you want to forward. For example:
309
326
310
327
``` console
311
328
$ iptables -I DOCKER-USER -i src_if -o dst_if -j ACCEPT
312
329
```
313
330
331
+ > [ !WARNING]
332
+ >
333
+ > In releases older than 28.0.0, Docker always set the default policy of the
334
+ > IPv6 ` FORWARD ` chain to ` DROP ` . In release 28.0.0 and newer, it will only
335
+ > set that policy if it enables IPv6 forwarding itself. This has always been
336
+ > the behaviour for IPv4 forwarding.
337
+ >
338
+ > If IPv6 forwarding is enabled on your host before Docker starts, check your
339
+ > host's configuration to make sure it is still secure.
340
+
314
341
## Prevent Docker from manipulating iptables
315
342
316
343
It is possible to set the ` iptables ` or ` ip6tables ` keys to ` false ` in
0 commit comments