Site Tools


wiki:docker-networks

Table of Contents

Docker Networks

Networks allow containers to communicate. By default, containers on the same network can reach each other by service name. Create custom networks for isolation; bridge networks are best for most use cases. Compose automatically creates a shared network for all services.

$ docker network create mynet         # create a bridge network
$ docker run --network mynet myapp    # attach a container to the network
$ docker network connect mynet <id>   # add running container to network
$ docker network ls                   # list networks
$ docker network inspect mynet        # inspect network details

Containers on the same network resolve each other's service name via DNS, so you can ping myapp from another container without knowing its IP. The default bridge network has limitations—use custom networks for better service discovery. You can also use host networks (container uses host's network directly) or overlay networks for swarm mode.

wiki/docker-networks.md · Last modified: by 127.0.0.1