Loading Depth Study
Preparing your workspace
Docker networks allow containers to communicate using isolated virtual networking and container names as discoverable addresses.
Applications are often split into several containers such as a web server, API, database, and cache. Docker networks allow those containers to communicate without exposing every internal service to the host or public internet. Containers on the same user-defined network can normally communicate using service or container names. This is an important foundation for multi-container applications.
A Node.js API container can connect to a PostgreSQL container using the database service name instead of localhost.
docker network create app-network docker run -d --name db --network app-network postgres docker run -d --name api --network app-network node-app
Both containers join the same Docker network and can communicate through the network.