docker-compose networking
default network
docker compose creates a bridge network by default.
services can communicate using service names as hostnames.
custom bridge network
create a custom bridge network with specific configurations:
key properties:
driver
: network driver (bridge, overlay, host, macvlan)driver_opts
: driver-specific optionsipam
: ip address management settings
host network
use the host’s network stack:
port exposure
expose ports to the host:
ports
: publish container ports to hostexpose
: expose ports without publishing to host
external networks
join an existing network:
network aliases
create service aliases:
default network configuration
configure the default network:
disable networking
isolate a service:
custom dns
specify custom dns servers: