Docker networking

Published: Tuesday, 14 July 2020
  • Jurn Ho

Docker containers will often need to communicate to other servers. Networking will enable this.

Network design is part of deployment architecture and can help with container isolation.

Bridge networks

A bridge network is a subnet on the host, e.g.

Creating a network

To add a new network named example_network with a subnet, run:

$ docker network create --subnet example_network

This creates the network on the host,

Running a container in a network

To start a container inside a given network, use the --network option, for example:

$ docker container run --network example_network httpd:2.4
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using

It will be assigned an IP within the network’s subnet.

If the --network option is not specified then it will be run in Docker’s default bridge network.

To start a container with a specific IP and network, use the --ip and --network options.

$ docker container run --network example_network --ip ubuntu cat /etc/hosts       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters     cdbce911318d

The above will start a new ubuntu container and assign it IP The /etc/hosts file shows config that docker added into the container.