In this step, you will run two different alpine containers on the same Docker host and do some tests to understand how they communicate with each other. You need to have Docker installed and running.
Open a terminal window. You can list current networks by running
docker network ls
The default bridge network is listed, along with host and none. The latter two are not fully-fledged networks, but are used to start a container connected directly to the Docker daemon host’s networking stack, or to start a container with no network devices. This tutorial will connect two containers to the bridge network.
Task: Connect To Network
When we launch new containers, we can use the --net attribute to assign which network they should be connected else the containers connect to the default bridge network.
Running following command to start two alpine containers.
docker run -dit --name alpine1 alpine ash
docker run -dit --name alpine2 alpine ash
Inspect the bridge network to see what containers are connected to it
docker network inspect bridge