diff between networks and network_mode
tags: learning linux diff-between
content
networks:
- it’s used to connect containers to custom networks
- the self-defined network, containers in the same network can communicate to each other via service’s name
- it creates isolated network segments
- a container can be connected to multiple networks
services:
web:
image: nginx
networks:
- frontend
- backend
# nginx is connected to two networksnetwork_mode:
- attach a container to the network stack of another container or service
- available values
bridge(default): gets its own network namespacenone: disable network, container is isolated, no networking at allhost: shares host’s network completely, uses host’s ip addresscontainer:<name>: uses the network of another containerservice:<name>: uses the network of another service
differences:
networksis for connecting containersnetwork_modechanges the fundamental networking behavior- containers are not just connected, they are literally using the same network stack
- as if they’re the same container