Containers do not live alone. They talk to databases, APIs, and other services. Docker networking makes this possible.
Docker automatically creates a bridge network. All containers can communicate inside it.
docker network ls
docker network create mynetwork
docker run -d --name backend --network mynetwork nginx
docker run -d --name frontend --network mynetwork nginx
Now containers can talk using container names:
curl http://backend
docker run -d -p 8080:80 nginx
This maps host port 8080 to container port 80.
Only expose ports that are required. Every open port is a risk.
Next, we move towards multi-container setups using Docker Compose.
Next: Docker Compose →