- The three core elements are sandbox, endpoint, and network
- Execute this command:
$ docker network create --driver bridge frontend
- Run this command:
$ docker container run -d --name n1 \
--network frontend -p 8080:80 nginx:alpine
$ docker container run -d --name n2 \
--network frontend -p 8081:80 nginx:alpine
Test that both Nginx instances are up and running:
$ curl -4 localhost:8080
$ curl -4 localhost:8081
You should be seeing the welcome page of Nginx in both cases.
- To get the IPs of all attached containers, run:
$ docker network inspect frontend | grep IPv4Address
You should see something similar to the following:
"IPv4Address": "172.18.0.2/16",
"IPv4Address": "172.18.0.3/16",
To get the subnet used by the network, use the following (for example):
$ docker network inspect frontend | grep subnet
You should receive something along the lines of the following (obtained from the previous example):
"Subnet": "172.18.0.0/16",
- The host network allows us to run a container in the networking namespace of the host.
- Only use this network for debugging purposes or when building a system-level tool. Never use the host network for an application container running production!
- The none network is basically saying that the container is not attached to any network. It should be used for containers that do not need to communicate with other containers and do not need to be accessed from outside.
- The none network could e.g. be used for a batch process running in a container that only needs access to local resources such as files which could be accessed via a host mounted volume.