Skip to content

Commit fb9e9e0

Browse files
committed
Networking overview - clarifications and gentler intro.
Signed-off-by: Rob Murray <[email protected]>
1 parent ad5db5b commit fb9e9e0

File tree

1 file changed

+91
-65
lines changed

1 file changed

+91
-65
lines changed

content/manuals/engine/network/_index.md

Lines changed: 91 additions & 65 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 --name=container3 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:
5479

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. |
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. |
6388

64-
For more information about the different drivers, see [Network drivers
65-
overview](./drivers/_index.md).
89+
More information can be found in the network driver specific pages, including
90+
their configuration options and details about their functionality.
91+
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 NIC. 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,40 +131,16 @@ $ 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+
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.
136144
This creates a firewall rule in the host,
137145
mapping a container port to a port on the Docker host to the outside world.
138146
Here are some examples:
@@ -165,11 +173,6 @@ Here are some examples:
165173
> > For more information, see
166174
> > [moby/moby#45610](https://github.com/moby/moby/issues/45610)
167175
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-
173176
Ports on the host's IPv6 addresses will map to the container's IPv4 address
174177
if no host IP is given in a port mapping, the bridge network is IPv4-only,
175178
and `--userland-proxy=true` (default).
@@ -237,7 +240,30 @@ containers. To pass additional hosts into a container, refer to [add entries to
237240
container hosts file](/reference/cli/docker/container/run.md#add-host) in the
238241
`docker run` reference documentation.
239242

240-
## Proxy server
243+
## Container networks
241244

242-
If your container needs to use a proxy server, see
243-
[Use a proxy server](/manuals/engine/daemon/proxy.md).
245+
In addition to user-defined networks, you can attach a container to another
246+
container's networking stack directly, using the `--network
247+
container:<name|id>` flag format.
248+
249+
The following flags aren't supported for containers using the `container:`
250+
networking mode:
251+
252+
- `--add-host`
253+
- `--hostname`
254+
- `--dns`
255+
- `--dns-search`
256+
- `--dns-option`
257+
- `--mac-address`
258+
- `--publish`
259+
- `--publish-all`
260+
- `--expose`
261+
262+
The following example runs a Redis container, with Redis binding to
263+
`localhost`, then running the `redis-cli` command and connecting to the Redis
264+
server over the `localhost` interface.
265+
266+
```console
267+
$ docker run -d --name redis example/redis --bind 127.0.0.1
268+
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
269+
```

0 commit comments

Comments
 (0)