CloudLinux.ro
Docker & containers

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 pricing

Related tutorials