Docker Networks Explained
Docker networks allow containers to communicate with each other, the host, and external systems. This guide explains bridge networks, host network, custom networks, DNS, and port publishing.
Quick answer
- Network — Use case
- bridge — Default single-host container networking.
- custom bridge — Recommended for app containers that need DNS-based communication.
- host — Container shares host network stack.
- none — No network access.
List networks
docker network ls
Create a custom network
docker network create app_net
Run containers on the same network
docker run -d --name redis --network app_net redis:7 docker run -it --rm --network app_net alpine sh
Inside the Alpine container, you can reach Redis using the container name redis .
apk add --no-cache redis redis-cli -h redis ping
Port mapping
Port mapping exposes a container port on the host machine.
docker run -d --name web -p 8080:80 nginx
Here, host port 8080 maps to container port 80 .
Inspect a network
docker network inspect app_net
Connect and disconnect containers
docker network connect app_net web docker network disconnect app_net web
Common networking problems
- Problem — Likely cause — Fix
- Cannot access app from browser — Port not published — Use -p HOST:CONTAINER .
- Containers cannot resolve names — Not on same custom network — Use a custom network.
- Port already allocated — Host port already in use — Choose another host port.
Best practices
- Use custom bridge networks for related containers.
- Expose only required ports.
- Use container names or Compose service names for internal communication.
- Avoid host network unless you really need it.
- Document port mappings clearly.
Related Melochip guides
- Docker Learning Path
- Docker Compose Beginner Guide
- Kubernetes Cluster Setup Guide
Official references
- Docker networking documentation
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn Docker registries, image tags, Docker Hub, private registries, login, push, pull, naming rules, CI/CD us...
2 min read · Sep 17, 2026
Learn Docker environment variables and secrets, including docker run -e, env files, Compose environment, secre...
2 min read · Sep 17, 2026
Prepare for Docker interviews with practical questions and real-time scenarios covering images, containers, Do...
2 min read · Sep 17, 2026
Learn Docker security best practices for images, containers, users, secrets, registries, scanning, least privi...
2 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.