Networking
Network Bridges
A network bridge in Docker is a virtual network that allows containers to communicate with each other while isolating them from the host network and other networks.
By default, if no network is specified when a container is created, it will connect to the default docker network bridge, often called docker0
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
Unless otherwise specified, all containers will be connected to this network bridge, allowing for communication between containers over the local bridge network.
Creating a Network Bridge
By default, Docker will create the docker0 network bridge. But, what if I want to create additional Docker networks?
In this scenario, we can use the docker network create function.
Port Publishing & Mapping
Each docker container is assigned its own internal IP on the bridge network. The container can then publish a port which it's service/process can be accessed on. In this example, lets say I have a webapp running in a docker container on port 5000 on the internal IP 172.168.1.110. I want this web app to be accessible via port 80 on the host;
Map a container port to host port
Map port 80 on the host, to 5000 on the container.
docker run -p80:5000 containername