Networking is an important part of Docker. By default, Docker comes with three networks that we can inspect by executing the following command:
docker network ls
This should produce output similar to the following:
Let's explain the different networks:
bridge: This is the default network. It is an entirely different stack from the host machine with a different IP range in the
bridgemode (the host machine acts as a
routerfor the containers in this network). The containers created without specifying the network are attached to the default bridge network.
host: In this network, containers share the network stack with the Docker host. If you inspect the configuration in the container, you will find that it is the exactly the same as in the Docker host.
none: This is easy to guess; the container gets attached to no network: just the loopback interface in the container.
Now it is time to look at some examples. We are going to use
busybox, which is the
swiss army knife of the Docker...