Introduction

Docker Networking is a feature that allows Docker containers to communicate with each other and the outside world. It is possible to create user-defined networks to isolate the containers and control the communication between them. They can be created manually via docker network create or automatically by Docker Compose.

Types

Default bridge

  • Containers can communicate with each other
  • Needs to manually expose the ports
  • No DNS

User-defined bridge

  • Containers can communicate with each other
  • Exposes the ports automatically
  • Automatic DNS with the name of the containers

Essential Commands

Create

Creates a user-defined bridge

sudo docker network create name_of_the_network

List

Lists all the networks

sudo docker network ls

Inspect

Shows the containers using the network and their mac addresses, ip addresses and other configurations

sudo docker inspect name_of_the_network