Table of Contents
Docker networking controls how containers communicate with each other, the host system, and the public internet. Understanding this is critical for exposing services securely on a VPS.
Step 1: Understand Docker Network Types
Docker uses different network drivers depending on your setup.
bridge → default local container networking
host → container shares host network
none → no networking
overlay → multi-host (Swarm / cluster)
Most VPS setups rely on the bridge network.
Step 2: List Existing Docker Networks
View all available Docker networks.
docker network ls
The default bridge network is usually named bridge.
Step 3: Inspect a Docker Network
Inspect network details such as IP ranges and connected containers.
docker network inspect bridge
This shows container IPs, gateways, and subnet configuration.
Step 4: How Containers Access the Internet
Containers use NAT through the host to reach external networks. Docker automatically configures iptables rules for this.
iptables -t nat -L -n
Outbound traffic is masqueraded through the VPS public IP.
Step 5: Expose Container Ports to the VPS
Port mapping allows external access to containers.
docker run -d -p 80:3000 my-app
Traffic on port 80 of the VPS is forwarded to port 3000 inside the container.
Step 6: Container-to-Container Communication
Containers on the same network can reach each other by name.
docker network create app-network
docker run -d --name api --network app-network api-image
docker run -d --name web --network app-network web-image
The web container can reach api using its name.
Step 7: Common Docker Networking Issues on VPS
Typical problems include blocked ports, firewall conflicts, or incorrect bindings.
ss -tulnp
docker ps
docker inspect container_name
You may also want to review this related article: How to Fix Services That Fail After Server Reboot
Optional Step: Use a Reverse Proxy Instead of Port Mapping
For multiple containers, a reverse proxy simplifies networking.
docker run -d -p 80:80 nginx
This allows multiple services to share standard ports cleanly.
