Skip to content

Commit c6dd8d8

Browse files
committed
network: add container networking intro from docker run reference
This change adds more introductory information about container networking to the networking overview page, moving it from the docker run reference page. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 89bdcc0 commit c6dd8d8

File tree

1 file changed

+80
-15
lines changed

1 file changed

+80
-15
lines changed

content/network/_index.md

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,78 @@ aliases:
1616
Container networking refers to the ability for containers to connect to and
1717
communicate with each other, or to non-Docker workloads.
1818

19-
A container has no information about what kind of network it's attached to,
20-
or whether their peers are also Docker workloads or not.
21-
A container only sees a network interface with an IP address,
22-
a gateway, a routing table, DNS services, and other networking details.
23-
That is, unless the container uses the `none` network driver.
19+
Containers have networking enabled by default, and they can make outgoing
20+
connections. A container has no information about what kind of network it's
21+
attached to, or whether their peers are also Docker workloads or not. A
22+
container only sees a network interface with an IP address, a gateway, a
23+
routing table, DNS services, and other networking details. That is, unless the
24+
container uses the `none` network driver.
2425

2526
This page describes networking from the point of view of the container,
2627
and the concepts around container networking.
2728
This page doesn't describe OS-specific details about how Docker networks work.
2829
For information about how Docker manipulates `iptables` rules on Linux,
2930
see [Packet filtering and firewalls](packet-filtering-firewalls.md).
3031

32+
## User-defined networks
33+
34+
You can create custom, user-defined networks, and connect multiple containers
35+
to the same network. Once connected to a user-defined network, containers can
36+
communicate using only another container's IP address or name.
37+
38+
The following example creates a network using the `bridge` network driver and
39+
running a container in the created network:
40+
41+
```console
42+
$ docker network create -d bridge my-net
43+
$ docker run --network=my-net -itd --name=container3 busybox
44+
```
45+
46+
### Drivers
47+
48+
The following network drivers are available by default, and provide core
49+
networking functionality:
50+
51+
| Driver | Description |
52+
| :-------- | :----------------------------------------------------------------------- |
53+
| `bridge` | The default network driver. |
54+
| `host` | Remove network isolation between the container and the Docker host. |
55+
| `none` | Completely isolate a container from the host and other containers. |
56+
| `overlay` | Overlay networks connect multiple Docker daemons together. |
57+
| `ipvlan` | IPvlan networks provide full control over both IPv4 and IPv6 addressing. |
58+
| `macvlan` | Assign a MAC address to a container. |
59+
60+
For more information about the different drivers, see [Network drivers
61+
overview](./drivers/_index.md).
62+
63+
## Container networks
64+
65+
In addition to user-defined networks, you can attach a container to another
66+
container's networking stack directly, using the `--network
67+
container:<name|id>` flag format.
68+
69+
The following flags aren't supported for containers using the `container:`
70+
networking mode:
71+
72+
- `--add-host`
73+
- `--hostname`
74+
- `--dns`
75+
- `--dns-search`
76+
- `--dns-option`
77+
- `--mac-address`
78+
- `--publish`
79+
- `--publish-all`
80+
- `--expose`
81+
82+
The following example runs a Redis container, with Redis binding to
83+
`localhost`, then running the `redis-cli` command and connecting to the Redis
84+
server over the `localhost` interface.
85+
86+
```console
87+
$ docker run -d --name redis example/redis --bind 127.0.0.1
88+
$ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1
89+
```
90+
3191
## Published ports
3292

3393
By default, when you create or run a container using `docker create` or `docker run`,
@@ -38,12 +98,12 @@ This creates a firewall rule in the host,
3898
mapping a container port to a port on the Docker host to the outside world.
3999
Here are some examples:
40100

41-
| Flag value | Description |
42-
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
43-
| `-p 8080:80` | Map port `8080` on the Docker host to TCP port `80` in the container. |
101+
| Flag value | Description |
102+
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
103+
| `-p 8080:80` | Map port `8080` on the Docker host to TCP port `80` in the container. |
44104
| `-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. |
45105
| `-p 8080:80/udp` | Map port `8080` on the Docker host to UDP port `80` in the container. |
46-
| `-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.|
106+
| `-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. |
47107

48108
> **Important**
49109
>
@@ -90,8 +150,11 @@ you can use the `--alias` flag to specify an additional network alias for the co
90150
91151
## DNS services
92152
93-
By default, containers inherit the DNS settings of the host,
94-
as defined in the `/etc/resolv.conf` configuration file.
153+
Containers use the same DNS servers as the host by default, but you can
154+
override this with `--dns`.
155+
156+
By default, containers inherit the DNS settings as defined in the
157+
`/etc/resolv.conf` configuration file.
95158
Containers that attach to the default `bridge` network receive a copy of this file.
96159
Containers that attach to a
97160
[custom network](network-tutorial-standalone.md#use-user-defined-bridge-networks)
@@ -128,10 +191,12 @@ resolution.
128191
129192
### Custom hosts
130193
131-
Custom hosts, defined in `/etc/hosts` on the host machine, aren't inherited by containers.
132-
To pass additional hosts into container, refer to
133-
[add entries to container hosts file](../engine/reference/commandline/run.md#add-host)
134-
in the `docker run` reference documentation.
194+
Your container will have lines in `/etc/hosts` which define the hostname of the
195+
container itself, as well as `localhost` and a few other common things. Custom
196+
hosts, defined in `/etc/hosts` on the host machine, aren't inherited by
197+
containers. To pass additional hosts into container, refer to [add entries to
198+
container hosts file](../engine/reference/commandline/run.md#add-host) in the
199+
`docker run` reference documentation.
135200
136201
## Proxy server
137202

0 commit comments

Comments
 (0)