Skip to content

Commit b0e9607

Browse files
authored
Merge pull request #23215 from robmry/moby_networking_tweaks
Engine networking updates for moby 29.0
2 parents 170ae6d + 2b123b9 commit b0e9607

File tree

6 files changed

+860
-474
lines changed

6 files changed

+860
-474
lines changed

content/manuals/engine/network/_index.md

Lines changed: 92 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,85 @@ aliases:
1818
---
1919

2020
Container networking refers to the ability for containers to connect to and
21-
communicate with each other, or to non-Docker workloads.
21+
communicate with each other, and with non-Docker network services.
2222

2323
Containers have networking enabled by default, and they can make outgoing
2424
connections. A container has no information about what kind of network it's
25-
attached to, or whether their peers are also Docker workloads or not. A
25+
attached to, or whether its network peers are also Docker containers. A
2626
container only sees a network interface with an IP address, a gateway, a
27-
routing table, DNS services, and other networking details. That is, unless the
28-
container uses the `none` network driver.
27+
routing table, DNS services, and other networking details.
2928

3029
This page describes networking from the point of view of the container,
3130
and the concepts around container networking.
32-
This page doesn't describe OS-specific details about how Docker networks work.
33-
For information about how Docker manipulates `iptables` rules on Linux,
34-
see [Packet filtering and firewalls](packet-filtering-firewalls.md).
31+
32+
When Docker Engine on Linux starts for the first time, it has a single
33+
built-in network called the "default bridge" network. When you run a
34+
container with no `--network` option, it is connected to the default bridge.
35+
36+
Containers attached to the default bridge have access to network services
37+
outside the Docker host. They use "masquerading" which means, if the
38+
Docker host has Internet access, no additional configuration is needed
39+
for the container to have Internet access.
40+
41+
For example, to run a container on the default bridge network, and have
42+
it ping an Internet host:
43+
44+
```console
45+
$ docker run --rm -ti busybox ping -c1 docker.com
46+
PING docker.com (23.185.0.4): 56 data bytes
47+
64 bytes from 23.185.0.4: seq=0 ttl=62 time=6.564 ms
48+
49+
--- docker.com ping statistics ---
50+
1 packets transmitted, 1 packets received, 0% packet loss
51+
round-trip min/avg/max = 6.564/6.564/6.564 ms
52+
```
3553

3654
## User-defined networks
3755

38-
You can create custom, user-defined networks, and connect multiple containers
39-
to the same network. Once connected to a user-defined network, containers can
40-
communicate with each other using container IP addresses or container names.
56+
With the default configuration, containers attached to the default
57+
bridge network have unrestricted network access to each other using
58+
container IP addresses. They cannot refer to each other by name.
59+
60+
It can be useful to separate groups of containers that should have full
61+
access to each other, but restricted access to containers in other groups.
62+
63+
You can create custom, user-defined networks, and connect groups of containers
64+
to the same network. Once connected to a user-defined network, containers
65+
can communicate with each other using container IP addresses or container names.
4166

4267
The following example creates a network using the `bridge` network driver and
43-
running a container in the created network:
68+
runs a container in that network:
4469

4570
```console
4671
$ docker network create -d bridge my-net
47-
$ docker run --network=my-net -itd --name=container3 busybox
72+
$ docker run --network=my-net -it busybox
4873
```
4974

5075
### Drivers
5176

52-
The following network drivers are available by default, and provide core
53-
networking functionality:
77+
Docker Engine has a number of network drivers, as well as the default "bridge".
78+
On Linux, the following built-in network drivers are available:
79+
80+
| Driver | Description |
81+
|:--------------------------------|:--------------------------------------------------------------------|
82+
| [bridge](./drivers/bridge.md) | The default network driver. |
83+
| [host](./drivers/host.md) | Remove network isolation between the container and the Docker host. |
84+
| [none](./drivers/none.md) | Completely isolate a container from the host and other containers. |
85+
| [overlay](./drivers/overlay.md) | Swarm Overlay networks connect multiple Docker daemons together. |
86+
| [ipvlan](./drivers/ipvlan.md) | Connect containers to external VLANs. |
87+
| [macvlan](./drivers/macvlan.md) | Containers appear as devices on the host's network. |
5488

55-
| Driver | Description |
56-
| :-------- | :----------------------------------------------------------------------- |
57-
| `bridge` | The default network driver. |
58-
| `host` | Remove network isolation between the container and the Docker host. |
59-
| `none` | Completely isolate a container from the host and other containers. |
60-
| `overlay` | Overlay networks connect multiple Docker daemons together. |
61-
| `ipvlan` | IPvlan networks provide full control over both IPv4 and IPv6 addressing. |
62-
| `macvlan` | Assign a MAC address to a container. |
89+
More information can be found in the network driver specific pages, including
90+
their configuration options and details about their functionality.
6391

64-
For more information about the different drivers, see [Network drivers
65-
overview](./drivers/_index.md).
92+
Native Windows containers have a different set of drivers, see
93+
[Windows container network drivers](https://learn.microsoft.com/en-us/virtualization/windowscontainers/container-networking/network-drivers-topologies).
6694

6795
### Connecting to multiple networks
6896

69-
A container can be connected to multiple networks.
97+
Connecting a container to a network can be compared to connecting an Ethernet
98+
cable to a physical host. Just as a host can be connected to multiple Ethernet
99+
networks, a container can be connected to multiple Docker networks.
70100

71101
For example, a frontend container may be connected to a bridge network
72102
with external access, and a
@@ -78,6 +108,8 @@ A container may also be connected to different types of network. For example,
78108
an `ipvlan` network to provide internet access, and a `bridge` network for
79109
access to local services.
80110

111+
Containers can also share networking stacks, see [Container networks](#container-networks).
112+
81113
When sending packets, if the destination is an address in a directly connected
82114
network, packets are sent to that network. Otherwise, packets are sent to
83115
a default gateway for routing to their destination. In the example above,
@@ -99,84 +131,20 @@ $ docker run --network name=gwnet,gw-priority=1 --network anet1 --name myctr myi
99131
$ docker network connect anet2 myctr
100132
```
101133

102-
## Container networks
103-
104-
In addition to user-defined networks, you can attach a container to another
105-
container's networking stack directly, using the `--network
106-
container:<name|id>` flag format.
107-
108-
The following flags aren't supported for containers using the `container:`
109-
networking mode:
110-
111-
- `--add-host`
112-
- `--hostname`
113-
- `--dns`
114-
- `--dns-search`
115-
- `--dns-option`
116-
- `--mac-address`
117-
- `--publish`
118-
- `--publish-all`
119-
- `--expose`
120-
121-
The following example runs a Redis container, with Redis binding to
122-
`localhost`, then running the `redis-cli` command and connecting to the Redis
123-
server over the `localhost` interface.
124-
125-
```console
126-
$ docker run -d --name redis example/redis --bind 127.0.0.1
127-
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
128-
```
129-
130134
## Published ports
131135

132-
By default, when you create or run a container using `docker create` or `docker run`,
133-
containers on bridge networks don't expose any ports to the outside world.
134-
Use the `--publish` or `-p` flag to make a port available to services
135-
outside the bridge network.
136-
This creates a firewall rule in the host,
137-
mapping a container port to a port on the Docker host to the outside world.
138-
Here are some examples:
139-
140-
| Flag value | Description |
141-
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
142-
| `-p 8080:80` | Map port `8080` on the Docker host to TCP port `80` in the container. |
143-
| `-p 192.168.1.100:8080:80` | Map port `8080` on the Docker host IP `192.168.1.100` to TCP port `80` in the container. |
144-
| `-p 8080:80/udp` | Map port `8080` on the Docker host to UDP port `80` in the container. |
145-
| `-p 8080:80/tcp -p 8080:80/udp` | Map TCP port `8080` on the Docker host to TCP port `80` in the container, and map UDP port `8080` on the Docker host to UDP port `80` in the container. |
146-
147-
> [!IMPORTANT]
148-
>
149-
> Publishing container ports is insecure by default. Meaning, when you publish
150-
> a container's ports it becomes available not only to the Docker host, but to
151-
> the outside world as well.
152-
>
153-
> If you include the localhost IP address (`127.0.0.1`, or `::1`) with the
154-
> publish flag, only the Docker host and its containers can access the
155-
> published container port.
156-
>
157-
> ```console
158-
> $ docker run -p 127.0.0.1:8080:80 -p '[::1]:8080:80' nginx
159-
> ```
160-
>
161-
> > [!WARNING]
162-
> >
163-
> > In releases older than 28.0.0, hosts within the same L2 segment (for example,
164-
> > hosts connected to the same network switch) can reach ports published to localhost.
165-
> > For more information, see
166-
> > [moby/moby#45610](https://github.com/moby/moby/issues/45610)
167-
168-
If you want to make a container accessible to other containers,
169-
it isn't necessary to publish the container's ports.
170-
You can enable inter-container communication by connecting the containers to the
171-
same network, usually a [bridge network](./drivers/bridge.md).
172-
173-
Ports on the host's IPv6 addresses will map to the container's IPv4 address
174-
if no host IP is given in a port mapping, the bridge network is IPv4-only,
175-
and `--userland-proxy=true` (default).
136+
When you create or run a container using `docker create` or `docker run`, all
137+
ports of containers on bridge networks are accessible from the Docker host and
138+
other containers connected to the same network. Ports are not accessible from
139+
outside the host or, with the default configuration, from containers in other
140+
networks.
141+
142+
Use the `--publish` or `-p` flag to make a port available outside the host,
143+
and to containers in other bridge networks.
176144

177145
For more information about port mapping, including how to disable it and use
178146
direct routing to containers, see
179-
[packet filtering and firewalls](./packet-filtering-firewalls.md).
147+
[port publishing](./port-publishing.md).
180148

181149
## IP address and hostname
182150

@@ -237,7 +205,30 @@ containers. To pass additional hosts into a container, refer to [add entries to
237205
container hosts file](/reference/cli/docker/container/run.md#add-host) in the
238206
`docker run` reference documentation.
239207

240-
## Proxy server
208+
## Container networks
209+
210+
In addition to user-defined networks, you can attach a container to another
211+
container's networking stack directly, using the `--network
212+
container:<name|id>` flag format.
213+
214+
The following flags aren't supported for containers using the `container:`
215+
networking mode:
241216

242-
If your container needs to use a proxy server, see
243-
[Use a proxy server](/manuals/engine/daemon/proxy.md).
217+
- `--add-host`
218+
- `--hostname`
219+
- `--dns`
220+
- `--dns-search`
221+
- `--dns-option`
222+
- `--mac-address`
223+
- `--publish`
224+
- `--publish-all`
225+
- `--expose`
226+
227+
The following example runs a Redis container, with Redis binding to
228+
127.0.0.1, then running the `redis-cli` command and connecting to the Redis
229+
server over 127.0.0.1.
230+
231+
```console
232+
$ docker run -d --name redis redis --bind 127.0.0.1
233+
$ docker run --rm -it --network container:redis redis redis-cli -h 127.0.0.1
234+
```

content/manuals/engine/network/drivers/bridge.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@ aliases:
1111
- /network/drivers/bridge/
1212
---
1313

14-
In terms of networking, a bridge network is a Link Layer device
15-
which forwards traffic between network segments. A bridge can be a hardware
16-
device or a software device running within a host machine's kernel.
14+
A Docker bridge network has an IPv4 subnet and, optionally, an IPv6 subnet.
15+
Each container connected to the bridge network has a network interface with
16+
addresses in the network's subnets. By default, it:
17+
- Allows unrestricted network access to containers in the network from
18+
the host, and from other containers connected to the same bridge network.
19+
- Blocks access from containers in other networks and from outside the
20+
Docker host.
21+
- Uses masquerading to give containers external network access. Devices on
22+
the host's external networks only see the IP address of the Docker host.
23+
- Supports port publishing, where network traffic is forwarded between
24+
container ports and ports on host IP addresses. The published ports
25+
can be accessed from outside the Docker host, on its IP addresses.
1726

1827
In terms of Docker, a bridge network uses a software bridge which lets
1928
containers connected to the same bridge network communicate, while providing
20-
isolation from containers that aren't connected to that bridge network. The
21-
Docker bridge driver automatically installs rules in the host machine so that
22-
containers on different bridge networks can't communicate directly with each
23-
other.
29+
isolation from containers that aren't connected to that bridge network. By
30+
default, the Docker bridge driver automatically installs rules in the host
31+
machine so that containers connected to different bridge networks can only
32+
communicate with each other using published ports.
2433

2534
Bridge networks apply to containers running on the same Docker daemon host.
2635
For communication among containers running on different Docker daemon hosts, you

0 commit comments

Comments
 (0)