Skip to content

Commit b6d6f36

Browse files
thaJeztahrobmryusha-mandya
authored
networking documentation changes for engine v29 (#23362)
<!--Delete sections as needed --> ## Description <!-- Tell us what you did and why --> ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review --------- Signed-off-by: Rob Murray <[email protected]> Co-authored-by: Rob Murray <[email protected]> Co-authored-by: Usha Mandya <[email protected]>
1 parent cb3d7db commit b6d6f36

File tree

6 files changed

+864
-474
lines changed

6 files changed

+864
-474
lines changed

content/manuals/engine/network/_index.md

Lines changed: 93 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,86 @@ 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 without the `--network` option, it is connected to the default
35+
bridge.
36+
37+
Containers attached to the default bridge have access to network services
38+
outside the Docker host. They use "masquerading" which means, if the
39+
Docker host has Internet access, no additional configuration is needed
40+
for the container to have Internet access.
41+
42+
For example, to run a container on the default bridge network, and have
43+
it ping an Internet host:
44+
45+
```console
46+
$ docker run --rm -ti busybox ping -c1 docker.com
47+
PING docker.com (23.185.0.4): 56 data bytes
48+
64 bytes from 23.185.0.4: seq=0 ttl=62 time=6.564 ms
49+
50+
--- docker.com ping statistics ---
51+
1 packets transmitted, 1 packets received, 0% packet loss
52+
round-trip min/avg/max = 6.564/6.564/6.564 ms
53+
```
3554

3655
## User-defined networks
3756

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

4268
The following example creates a network using the `bridge` network driver and
43-
running a container in the created network:
69+
runs a container in that network:
4470

4571
```console
4672
$ docker network create -d bridge my-net
47-
$ docker run --network=my-net -itd --name=container3 busybox
73+
$ docker run --network=my-net -it busybox
4874
```
4975

5076
### Drivers
5177

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

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. |
90+
More information can be found in the network driver specific pages, including
91+
their configuration options and details about their functionality.
6392

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

6796
### Connecting to multiple networks
6897

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

71102
For example, a frontend container may be connected to a bridge network
72103
with external access, and a
@@ -78,6 +109,8 @@ A container may also be connected to different types of network. For example,
78109
an `ipvlan` network to provide internet access, and a `bridge` network for
79110
access to local services.
80111

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

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-
130135
## Published ports
131136

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).
137+
When you create or run a container using `docker create` or `docker run`, all
138+
ports of containers on bridge networks are accessible from the Docker host and
139+
other containers connected to the same network. Ports are not accessible from
140+
outside the host or, with the default configuration, from containers in other
141+
networks.
142+
143+
Use the `--publish` or `-p` flag to make a port available outside the host,
144+
and to containers in other bridge networks.
176145

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

181150
## IP address and hostname
182151

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

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

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

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)