SkillSprout
Chapter 1 · Lesson 14
Intermediate
2 min read

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

TypeTypical use
BridgeMultiple containers on one Docker host
HostAvoid normal port mapping when supported
NoneNo network interface except loopback
OverlayCommunication across hosts in orchestration
MacvlanAttach containers to a physical network

For a beginner application, create a named bridge:

bash
docker network create backend-network
docker run -d --name api --network backend-network my-api
docker network inspect backend-network

Troubleshooting sequence

  1. Confirm the container is running:
bash
docker ps
docker logs api
  1. Confirm it listens on the expected port:
bash
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.

  1. Confirm network membership:
bash
docker inspect api --format '{{json .NetworkSettings.Networks}}'
docker network inspect backend-network
  1. Test DNS and reachability from another container:
bash
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:

bash
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