Docker Networking Explained: From the Default Bridge to Compose DNS
Why containers on the default bridge only find each other by IP, and how a Compose network resolves service names with built-in DNS.

Table of contents
Containers are isolated by default; Docker networks are what connect them to each other and to the outside world. Knowing the three main kinds solves most “my container can’t reach the database” problems.
The default bridge
A container started without any network settings joins the default bridge network. Its limitation: on the default bridge, containers can only reach each other by IP address, not by name.
User-defined networks and automatic DNS
When Compose starts a project, it creates a dedicated network for it, and on that network containers find each other by service name:
WORDPRESS_DB_HOST: db:3306
Here db is simply the service name from the Compose file. That built-in DNS is what lets services connect without any hard-coded IP addresses.
Host networking
With network_mode: host a container sits directly on the server’s own network stack, with no port isolation. That is useful for monitoring tools that need to see the server’s real traffic, but it is a poor security choice for web applications because it removes the container boundary.
Publishing ports
The -p flag, or ports: in Compose, takes the form host:container:
ports:
- "8080:80" # server port 8080 -> container port 80
The left-hand port is opened on the server. If port 80 on your server is free, "80:80" serves the site on the usual HTTP port. Be aware that published ports bypass UFW; see why UFW doesn’t block Docker.
Inspecting and debugging
docker network ls
docker network inspect wordpress-demo_wp-net
docker compose exec app ping -c2 db
If ping by service name works, the network layer is fine and the problem is in the application layer (password, database name and so on).



Comments
No comments yet. For technical questions, include the details (OS version, the exact error and the command you ran) to get a precise answer.