Skip to content

Commit 42decd8

Browse files
committedDec 11, 2024
Describe gateway selection in the networking overview.
Signed-off-by: Rob Murray <rob.murray@docker.com>
1 parent a056de8 commit 42decd8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎content/manuals/engine/network/_index.md

+34
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,40 @@ networking functionality:
6363
For more information about the different drivers, see [Network drivers
6464
overview](./drivers/_index.md).
6565

66+
### Connecting to multiple networks
67+
68+
A container can be connected to multiple networks.
69+
70+
For example, a frontend container may be connected to a bridge network
71+
with external access, and a `--internal` network to communicate with
72+
containers running backend services that do not need external network
73+
access.
74+
75+
A container may also be connected to different types of network. For example,
76+
an `ipvlan` network to provide internet access, and a `bridge` network for
77+
access to local services.
78+
79+
When sending packets, if the destination is an address in a directly connected
80+
network, packets are sent to that network. Otherwise, packets are sent to
81+
a default gateway for routing to their destination. In the example above,
82+
the `ipvlan` network's gateway must be the default gateway.
83+
84+
The default gateway is selected by docker, and may change each time a
85+
container's network connections change.
86+
To make docker choose a specific default gateway when creating the container
87+
or connecting a new network, set a gateway priority. See option `gw-priority`
88+
in [docker run](/reference/cli/docker/container/run.md) and
89+
[docker network connect](/reference/cli/docker/network/connect.md).
90+
91+
The default `gw-priority` is `0` and the gateway in the network with the
92+
highest priority is the default gateway. So, when a network should always
93+
be the default gateway, it is enough to set its `gw-priority` to `1`.
94+
95+
```console
96+
$ docker run --network name=gwnet,gw-priority=1 --network anet1 --name myctr myimage
97+
$ docker network connect anet2 myctr
98+
```
99+
66100
## Container networks
67101

68102
In addition to user-defined networks, you can attach a container to another

0 commit comments

Comments
 (0)