Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2021-11-18 21:38:42
Size: 398
Comment:
Revision 9 as of 2023-04-04 20:04:10
Size: 1945
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

'''Bridge networks''' are a type of networks used by `dockerd(8)`.
Line 11: Line 13:
All containers are attached to a network. If one is not specified, the default network is used. This network is special in that there is no name resolution; the only way to communicate between containers is their ephemeral IP addresses. By default, containers attach to bridge networks. See [[Docker/Networking|here]] to change that.

If a bridge network is not specified, the '''default network''' is used. This network is special in that there is no name resolution; the only way to communicate between containers is their ephemeral IP addresses.

Furthermore, the default network's use of [[Protocols/IP|IPv6]] mandatorily matches the `dockerd(8)` configuration. See [[Docker/Configuration#IPv6|here]] to enable it.
Line 17: Line 23:
== Creating Networks == == Custom Networks ==

Custom bridge networks can be created and destroyed like:

{{{
docker network create my-net
docker network rm my-net
}}}

Note that a network cannot be destroyed if any containers are attached to it. They must be explicitly detached first.

{{{
docker network disconnect my-net my-nginx
}}}

To enable IPv6 on a custom network, add the `--ipv6` option.



=== Attaching Containers ===

A container can be created on a custom network by specifying the `--network` option.

{{{
docker run --detach --name my-nginx \
  --network=my-net \
  nginx:latest
}}}

A running container can be attached to a custom network like:

{{{
docker network connect my-net my-nginx
}}}

Containers on a custom bridge network can communicate with each other by addressing the containers' names. For example, the above container would be accessible at `http://my-nginx`.

{{{
$ docker run --interactive --tty --name my-alpine \
    --network=my-net \
    alpine:latest
# apk add curl
[ ... ]
# curl http://my-nginx
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[ ... ]
}}}

Note that ''all'' ports are exposed.

----



== See also ==

[[Docker/Networking|Docker Networking]]

Docker Bridge Networks

Bridge networks are a type of networks used by dockerd(8).


Default Network

By default, containers attach to bridge networks. See here to change that.

If a bridge network is not specified, the default network is used. This network is special in that there is no name resolution; the only way to communicate between containers is their ephemeral IP addresses.

Furthermore, the default network's use of IPv6 mandatorily matches the dockerd(8) configuration. See here to enable it.


Custom Networks

Custom bridge networks can be created and destroyed like:

docker network create my-net
docker network rm my-net

Note that a network cannot be destroyed if any containers are attached to it. They must be explicitly detached first.

docker network disconnect my-net my-nginx

To enable IPv6 on a custom network, add the --ipv6 option.

Attaching Containers

A container can be created on a custom network by specifying the --network option.

docker run --detach --name my-nginx \
  --network=my-net \
  nginx:latest

A running container can be attached to a custom network like:

docker network connect my-net my-nginx

Containers on a custom bridge network can communicate with each other by addressing the containers' names. For example, the above container would be accessible at http://my-nginx.

$ docker run --interactive --tty --name my-alpine \
    --network=my-net \
    alpine:latest
# apk add curl
[ ... ]
# curl http://my-nginx
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[ ... ]

Note that all ports are exposed.


See also

Docker Networking


CategoryRicottone

Docker/BridgeNetworks (last edited 2023-04-04 23:03:31 by DominicRicottone)