Skip to content

Commit 0061342

Browse files
author
David Karlsson
committed
engine: describe iptables conflict with ufw
Signed-off-by: David Karlsson <david.karlsson@docker.com>
1 parent c49dd4b commit 0061342

File tree

8 files changed

+97
-49
lines changed

8 files changed

+97
-49
lines changed

_data/toc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,8 @@ manuals:
15541554
title: Keep containers alive during daemon downtime
15551555
- path: /config/daemon/troubleshoot/
15561556
title: Troubleshoot
1557-
- path: /network/iptables/
1558-
title: Docker and iptables
1557+
- path: /network/packet-filtering-firewalls/
1558+
title: Packet filtering and firewalls
15591559
- path: /config/daemon/remote-access/
15601560
title: Remote access
15611561
- path: /engine/context/working-with-contexts/

engine/install/debian.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ To get started with Docker Engine on Debian, make sure you
1717

1818
## Prerequisites
1919

20+
> **Note**
21+
>
22+
> If you use ufw to manage firewall settings, note that when you expose
23+
> container ports using Docker, those ports bypass any firewall rules that
24+
> you configure with ufw. See
25+
> [Docker and ufw](../../network/packet-filtering-firewalls.md#docker-and-ufw)
26+
> for details.
27+
2028
### OS requirements
2129

2230
To install Docker Engine, you need the 64-bit version of one of these Debian

engine/install/raspbian.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ To get started with Docker Engine on Raspbian, make sure you
1414

1515
## Prerequisites
1616

17+
> **Note**
18+
>
19+
> If you use ufw to manage firewall settings, note that when you expose
20+
> container ports using Docker, those ports bypass any firewall rules that
21+
> you configure with ufw. See
22+
> [Docker and ufw](../../network/packet-filtering-firewalls.md#docker-and-ufw)
23+
> for details.
24+
1725
### OS requirements
1826

1927
To install Docker Engine, you need the 64-bit version or 32-bit version of one of these Raspbian

engine/install/ubuntu.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ To get started with Docker Engine on Ubuntu, make sure you
2222

2323
## Prerequisites
2424

25+
> **Note**
26+
>
27+
> If you use ufw to manage firewall settings, note that when you expose
28+
> container ports using Docker, those ports bypass any firewall rules that
29+
> you configure with ufw. See
30+
> [Docker and ufw](../../network/packet-filtering-firewalls.md#docker-and-ufw)
31+
> for details.
32+
2533
### OS requirements
2634

2735
To install Docker Engine, you need the 64-bit version of one of these Ubuntu

network/drivers/bridge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ daemon. The following tables shows which options have equivalent flags in the
128128
| `com.docker.network.driver.mtu` | `--mtu` |
129129
| `com.docker.network.container_iface_prefix` | - |
130130

131+
The Docker daemon supports a `--bridge` flag, which you can use to define a
132+
custom network bridge. You use this option if you want to run multiple daemon
133+
instances on the same host. For details, see
134+
[Run multiple daemons](../../engine/reference/commandline/dockerd.md#run-multiple-daemons).
135+
131136
## Manage a user-defined bridge
132137

133138
Use the `docker network create` command to create a user-defined bridge

network/drivers/index.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ Docker's networking subsystem is pluggable, using drivers. Several drivers
88
exist by default, and provide core networking functionality:
99

1010
- `bridge`: The default network driver. If you don't specify a driver, this is
11-
the type of network you are creating. **Bridge networks are usually used when
12-
your applications run in standalone containers that need to communicate.** See
13-
[bridge networks](bridge.md).
11+
the type of network you are creating. Bridge networks are commonly used when
12+
your application runs in a container that needs to communicate with other
13+
containers on the same host. See [bridge networks](bridge.md).
1414

1515
- `host`: For standalone containers, remove network isolation between the
1616
container and the Docker host, and use the host's networking directly. See
1717
[use the host network](host.md).
1818

1919
- `overlay`: Overlay networks connect multiple Docker daemons together and
20-
enable swarm services to communicate with each other. You can also use overlay
21-
networks to facilitate communication between a swarm service and a standalone
22-
container, or between two standalone containers on different Docker daemons.
23-
This strategy removes the need to do OS-level routing between these
24-
containers. See [overlay networks](overlay.md).
20+
enable Swarm services and containers to communicate across nodes. This
21+
strategy removes the need to do OS-level routing.
22+
See [overlay networks](overlay.md).
2523

2624
- `ipvlan`: IPvlan networks give users total control over both IPv4 and IPv6
2725
addressing. The VLAN driver builds on top of that in giving operators complete
@@ -36,27 +34,32 @@ exist by default, and provide core networking functionality:
3634
through the Docker host's network stack. See
3735
[Macvlan networks](macvlan.md).
3836

39-
- `none`: For this container, disable all networking. Usually used in
40-
conjunction with a custom network driver. `none` is not available for swarm
41-
services. See
42-
[disable container networking](none.md).
37+
- `none`: For this container, disable all networking. `none` is not available
38+
for Swarm services. See [disable container networking](none.md).
4339

4440
- [Network plugins](/engine/extend/plugins_services/): You can install and use
4541
third-party network plugins with Docker.
4642

4743
### Network driver summary
4844

49-
- **User-defined bridge networks** are best when you need multiple containers to
50-
communicate on the same Docker host.
51-
- **Host networks** are best when the network stack should not be isolated from
52-
the Docker host, but you want other aspects of the container to be isolated.
53-
- **Overlay networks** are best when you need containers running on different
54-
Docker hosts to communicate, or when multiple applications work together using
55-
swarm services.
56-
- **Macvlan networks** are best when you are migrating from a VM setup or
57-
need your containers to look like physical hosts on your network, each with a
58-
unique MAC address.
59-
- **Third-party network plugins** allow you to integrate Docker with specialized
45+
- The default bridge network is commonly used for running containers that don't
46+
require custom networking configurations, such as container-to-container
47+
connectivity.
48+
- User-defined bridge networks enable on the same Docker host to communicate
49+
with each other. A user-defined network typically defines an isolated network
50+
for multiple containers belonging to a common project or component.
51+
- Host network shares the host's network with the container. When you use this
52+
driver, the container's network isn't isolated from the host.
53+
- Overlay networks are best when you need containers running on different
54+
Docker hosts to communicate, or when multiple applications work together
55+
using Swarm services.
56+
- Macvlan networks are best when you are migrating from a VM setup or need your
57+
containers to look like physical hosts on your network, each with a unique
58+
MAC address.
59+
- IPvlan is similar to Macvlan, but doesn't assign unique MAC addresses to
60+
containers. Consider using IPvlan when there's a restriction on the number of
61+
MAC addresses that can be assigned to a network interface or port.
62+
- Third-party network plugins allow you to integrate Docker with specialized
6063
network stacks.
6164

6265
## Networking tutorials

network/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This page describes networking from the point of view of the container.
2626
This page describes the concepts around container networking.
2727
This page doesn't describe OS-specific details about how Docker networks work.
2828
For information about how Docker manipulates `iptables` rules on Linux,
29-
see [Docker and iptables](iptables.md).
29+
see [Packet filtering and firewalls](packet-filtering-firewalls.md).
3030

3131
## Published ports
3232

@@ -35,7 +35,7 @@ the container doesn't expose any of its ports to the outside world.
3535
To make a port available to services outside of Docker,
3636
or to Docker containers running on a different network,
3737
use the `--publish` or `-p` flag.
38-
This creates a firewall rule in the container,
38+
This creates a firewall rule in the host,
3939
mapping a container port to a port on the Docker host to the outside world.
4040
Here are some examples:
4141

@@ -53,8 +53,7 @@ Here are some examples:
5353
> the outside world as well.
5454
>
5555
> To publish a container's port and only expose it to the Docker host, include
56-
> the localhost IP address in the port mapping command. On most systems, that
57-
> IP is `127.0.0.1`.
56+
> the localhost IP address (`127.0.0.1`) in the port mapping command.
5857
>
5958
> ```console
6059
> $ docker run -p 127.0.0.1:8080:80 nginx
@@ -64,8 +63,8 @@ Here are some examples:
6463
## IP address and hostname
6564
6665
By default, the container gets an IP address for every Docker network it attaches to.
67-
A container receives an IP address out of the IP pool of the network it attaches to.
68-
The Docker daemon effectively acts as a DHCP server for each container.
66+
A container receives an IP address out of the IP subnet of the network.
67+
The Docker daemon performs dynamic subnetting and IP address allocation for containers.
6968
Each network also has a default subnet mask and gateway.
7069
7170
When a container starts, it can only attach to a single network, using the `--network` flag.
@@ -110,11 +109,12 @@ work in a surprising or unexpected way. DNS lookup behavior depends on a number
110109
of different factors:
111110
112111
- Whether the container OS runs on [musl or glibc](https://wiki.musl-libc.org/functional-differences-from-glibc.html#Name_Resolver/DNS){: target="blank" rel="noopener" }
113-
- Whether the Docker daemon binary was [statically or dynamically linked](https://pkg.go.dev/net#hdr-Name_Resolution){: target="blank" rel="noopener" }
112+
- Whether the Docker daemon binary is [statically or dynamically linked](https://pkg.go.dev/net#hdr-Name_Resolution){: target="blank" rel="noopener" }
114113
- If dynamically linked, which version of glibc that's used
115114
- Whether or not [nsswitch.conf is present](https://tldp.org/LDP/nag2/x-087-2-resolv.library.html#X-087-2-RESOLV.NSSWITCH-CONF){: target="blank" rel="noopener" }
116115
117-
You may find that name resolution works as follows:
116+
Under most circumstances, name resolution with multiple nameservers should work
117+
as follows:
118118
119119
1. The container emits requests to **all** nameservers that you specify.
120120
2. The container uses the first response returned by any of the nameservers.

network/iptables.md renamed to network/packet-filtering-firewalls.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
2-
title: Docker and iptables
3-
description: The basics of how Docker works with iptables
4-
keywords: network, iptables
2+
title: Packet filtering and firewalls
3+
description: How Docker works with packet filtering, iptables, and firewalls
4+
keywords: network, iptables, firewall
5+
redirect_from:
6+
- /network/iptables/
57
---
68

79
On Linux, Docker manipulates `iptables` rules to provide network isolation.
@@ -28,9 +30,9 @@ before any rules Docker creates automatically.
2830

2931
Other rules added to the `FORWARD` chain, either manually, or by another
3032
iptables-based firewall, are evaluated after the `DOCKER-USER` and `DOCKER` chains.
31-
This means that if you expose a port through Docker,
32-
this port gets exposed no matter what rules your firewall has configured.
33-
If you want rules to apply even when a port gets exposed through Docker,
33+
This means that if you publish a port through Docker,
34+
this port gets published no matter what rules your firewall has configured.
35+
If you want rules to apply even when a port gets published through Docker,
3436
you must add these rules to the `DOCKER-USER` chain.
3537

3638
### Match the original IP and ports for requests
@@ -47,7 +49,7 @@ For example:
4749

4850
```console
4951
$ sudo iptables -I DOCKER-USER -p tcp -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
50-
$ sudo iptables -I DOCKER-USER -p tcp -m conntrack -ctorigsrc 1.2.3.4 --ctorigdstport 80 -j ACCEPT
52+
$ sudo iptables -I DOCKER-USER -p tcp -m conntrack --ctorigsrc 1.2.3.4 --ctorigdstport 80 -j ACCEPT
5153
```
5254

5355
> **Important**
@@ -110,17 +112,18 @@ For system integrators who wish to build the Docker runtime into other applicati
110112

111113
## Setting the default bind address for containers
112114

113-
The Docker daemon binds exposed container ports to the `0.0.0.0` address.
114-
When you publish a container's ports as follows:
115+
By default, the Docker daemon binds published container ports to the `0.0.0.0`
116+
address. When you publish a container's ports as follows:
115117

116118
```console
117119
docker run -p 8080:80 nginx
118120
```
119121

120-
On most systems, this exposes port 8080 to all network interfaces on the host,
121-
potentially making them available to the outside world.
122+
This publishes port 8080 to all network interfaces on the host, potentially
123+
making them available to the outside world. Unless you've disabled IPv6 at the
124+
kernel level, the port gets published on both IPv4 and IPv6.
122125

123-
You can change the default binding address for exposed container ports so that
126+
You can change the default binding address for published container ports so that
124127
they're only accessible to the Docker host by default. To do that, you can
125128
configure the daemon to use the loopback address (`127.0.0.1`) instead. You
126129
have two options for how to do this:
@@ -139,12 +142,12 @@ have two options for how to do this:
139142
}
140143
```
141144

142-
This changes the default binding port for all bridge networks to use the
143-
`127.0.0.1` address when you expose container ports.
145+
This changes the default binding port to `127.0.0.1` for published container
146+
ports on the default bridge network.
144147

145-
You can also configure this setting individually for each bridge network, using
148+
To configure this setting for user-defined bridge networks, use
146149
the `com.docker.network.bridge.host_binding_ipv4`
147-
[driver option](./drivers/bridge.md#options) for the bridge driver.
150+
[driver option](./drivers/bridge.md#options) when you create the network.
148151

149152
```console
150153
$ docker network create mybridge \
@@ -167,3 +170,16 @@ $ firewall-cmd --reload
167170
```
168171

169172
Restarting `dockerd` daemon inserts the interface into the `docker` zone.
173+
174+
## Docker and ufw
175+
176+
Uncomplicated Firewall (ufw) is a frontend that ships with Debian and Ubuntu,
177+
and it lets you manage firewall rules. Docker and ufw use iptables in ways
178+
that make them incompatible with each other.
179+
180+
When you publish a container's ports using Docker, traffic to and from that
181+
container gets diverted before it goes through the ufw firewall settings.
182+
Docker routes container traffic in the `nat` table, which means that packets
183+
are diverted before it reaches the `filter` table that ufw uses. Packets are
184+
routed before the firewall rules can be applied, effectively ignoring your
185+
firewall configuration.

0 commit comments

Comments
 (0)