Docker – Networks


How it works?

By default, each created container is connected to a private virtual network called bridge and containers can talk to each other.

This network routes through NAT on host machine, so that containers can communicate with the outside world.

Note that it’s recommended to create a virtual network for each app.


Networks management

Let’s create a network! To do that, we’ll use the following command :
docker network create mynetwork

Now, we want to check if our network was really created. for that we use the following command to list all networks :
docker network ls

Next step? Let’s make one of our container use this network.
docker network connect

If we change our mind, and wants to disconnect our container from this network, we use :
docker network disconnect

Get data about a network:
docker network inspect CONTAINER_NAME


Container network configuration

To get a container IP address, we use the inspect command as follow :
docker container inspect --format '{{ .NetworkSettings.IPAddress }}' CONTAINER_NAME

Get your container port :
docker container port CONTAINER_NAME

About the author

nyounes

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *