Network Types and Troubleshooting
Overview
Docker networks decide which containers can discover and reach one another. The bridge network is the normal choice for a local application, host networking bypasses normal isolation on supported platforms, and none networking disables external network access.
Detailed Notes
Network types
| Type | Typical use |
|---|---|
| Bridge | Multiple containers on one Docker host |
| Host | Avoid normal port mapping when supported |
| None | No network interface except loopback |
| Overlay | Communication across hosts in orchestration |
| Macvlan | Attach containers to a physical network |
For a beginner application, create a named bridge:
docker network create backend-network
docker run -d --name api --network backend-network my-api
docker network inspect backend-network
Troubleshooting sequence
- Confirm the container is running:
docker ps
docker logs api
- Confirm it listens on the expected port:
docker exec api sh -c "netstat -lnt" || true
docker port api
The netstat command is only available if the image includes it. This is why a diagnostic image may be needed.
- Confirm network membership:
docker inspect api --format '{{json .NetworkSettings.Networks}}'
docker network inspect backend-network
- Test DNS and reachability from another container:
docker run --rm --network backend-network curlimages/curl curl -v http://api:8080/health
If DNS fails, verify both containers share a network and the target name is correct. If DNS works but a connection fails, verify the target process listens on 8080 and no firewall or application allowlist rejects it.
Port conflicts
If Docker reports that a host port is allocated, another process or container owns it:
docker ps --format 'table {{.Names}} {{.Ports}}'
Choose a free host port, for example -p 8081:8080, or stop the conflicting container.
Common Interview Questions
Finished this lesson?
0 of 27 lessons done · 0% of the course

