How networking works in Docker
Updated 7/20/2026
Containers can communicate through Docker networks. A well-designed network isolates services and exposes only the ones you need.
1. Create a network
docker network create app_net
2. Connect containers
docker run -d --name db --network app_net mysql:8
docker run -d --name web --network app_net nginx
Now web can reach the database using the name db as a hostname, without exposing MySQL externally.
3. Isolation
Put the database on an internal network and the web server on a public one. Only the web server has access to both. That way MySQL is never directly reachable from the internet.
4. Useful commands
docker network ls
docker network inspect app_net
docker network connect app_net container
In Docker Compose
Compose automatically creates a network for the services in the file, so they reach each other by name. See Docker Compose.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to free up disk space used by Docker
Images, stopped containers and orphaned volumes can fill your disk. Here is how to clean them up safely.
Updated 7/20/2026Docker & containersHow to run your own private Docker registry
Host your own Docker images on a private server, without depending on external services.
Updated 7/20/2026Docker & containersDocker security best practices
Run safer containers: non-root users, official images, limited resources and protected secrets.
Updated 7/20/2026