What is a network in Docker?
A network in Docker is a mechanism that lets containers talk to each other and to the outside world. Docker creates isolated virtual networks where each container gets its own IP address and can securely interact with other services.
What this gives you:
Isolation
Containers in the same network see each other, while containers in another network do not. This improves security and manageability.
Communication by service name
Inside a Docker network, containers can reach each other not by IP, but by service name:
http://db:5432Built-in DNS
Docker resolves service names inside the network itself, nothing needs to be configured manually.
Example in docker-compose.yml:
services:
app:
image: myapp
networks:
- internal_net
db:
image: postgres
networks:
- internal_net
networks:
internal_net:The app and db containers end up in the same internal_net network and can communicate with each other.
Summary: a network in Docker is a virtual environment in which containers exchange data. It provides isolation, convenient interaction, and automatic DNS inside the environment.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.