Bird
Raised Fist0
Dockerdevops~5 mins

Bridge network default behavior in Docker - Commands & Configuration

Choose your learning style10 modes available
Introduction
Docker uses a bridge network by default to allow containers on the same host to communicate with each other. This network acts like a virtual switch connecting containers, isolating them from the outside unless explicitly exposed.
When you want multiple containers on the same machine to talk to each other easily without extra setup.
When you run a simple web app and a database container on the same host and want them connected.
When you need container isolation from the host network but still want internal communication.
When you want to test container networking locally without configuring custom networks.
When you want to expose only specific ports to the outside while keeping other container traffic private.
Commands
This command lists all Docker networks on your system, including the default bridge network.
Terminal
docker network ls
Expected OutputExpected
NETWORK ID NAME DRIVER SCOPE b3d3f6e8c1a2 bridge bridge local f7c8e9d7a123 host host local 9a8b7c6d5e4f none null local
This command runs an Nginx container detached, connected to the default bridge network automatically.
Terminal
docker run -d --name my-nginx nginx
Expected OutputExpected
a1b2c3d4e5f678901234567890abcdef1234567890abcdef1234567890abcdef
→
-d - Run container in detached mode (in background)
→
--name - Assign a name to the container for easier reference
This command shows detailed information about the default bridge network, including connected containers and IP ranges.
Terminal
docker network inspect bridge
Expected OutputExpected
[ { "Name": "bridge", "Id": "b3d3f6e8c1a2", "Created": "2024-06-01T12:00:00.000000000Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Containers": { "a1b2c3d4e5f678901234567890abcdef1234567890abcdef1234567890abcdef": { "Name": "my-nginx", "EndpointID": "e1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ]
This command tests connectivity from the container to the bridge network gateway, showing the default network allows communication.
Terminal
docker exec my-nginx ping -c 2 172.17.0.1
Expected OutputExpected
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data. 64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.123 ms 64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.110 ms --- 172.17.0.1 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 0.110/0.116/0.123/0.007 ms
→
-c 2 - Send 2 ping packets then stop
Key Concept

If you remember nothing else from this pattern, remember: Docker's default bridge network connects containers on the same host with isolated internal IPs and allows controlled external access.

Common Mistakes
Trying to access a container's exposed port from the host without publishing the port.
By default, containers on the bridge network are isolated from the host network and ports are not accessible externally unless published.
Use the -p flag with docker run to publish container ports to the host, e.g., docker run -d -p 8080:80 nginx.
Assuming containers on different hosts can communicate over the default bridge network.
The default bridge network is local to a single Docker host and does not span multiple machines.
Use overlay networks or other multi-host networking solutions for cross-host container communication.
Summary
The default bridge network connects containers on the same Docker host with isolated IP addresses.
Containers on this network can communicate internally but need port publishing to be accessed from outside.
Inspecting the bridge network shows connected containers and IP details for troubleshooting.

Practice

(1/5)
1. What is the default behavior of Docker's bridge network regarding container communication?
easy
A. Containers can communicate by container name without extra setup.
B. Containers cannot communicate with each other at all.
C. Containers can communicate with each other by IP address only.
D. Containers share the host network directly.

Solution

  1. Step 1: Understand bridge network basics

    The default bridge network connects containers on the same Docker host and allows communication by IP address.
  2. Step 2: Analyze name resolution behavior

    By default, containers on the bridge network cannot resolve each other's names without a custom network.
  3. Final Answer:

    Containers can communicate with each other by IP address only. -> Option C
  4. Quick Check:

    Bridge network communication = IP only [OK]
Hint: Default bridge allows IP communication, not name resolution [OK]
Common Mistakes:
  • Assuming container names resolve by default
  • Thinking containers share host network directly
  • Believing containers cannot communicate at all
2. Which Docker command shows the default bridge network details?
easy
A. docker info bridge
B. docker network ls
C. docker container ls
D. docker network inspect bridge

Solution

  1. Step 1: Identify command to inspect networks

    To see details of a specific network, use docker network inspect <network-name>.
  2. Step 2: Apply to default bridge network

    The default bridge network is named "bridge", so the command is docker network inspect bridge.
  3. Final Answer:

    docker network inspect bridge -> Option D
  4. Quick Check:

    Inspect bridge network = docker network inspect bridge [OK]
Hint: Inspect networks with 'docker network inspect <name>' [OK]
Common Mistakes:
  • Using 'docker container ls' to see networks
  • Trying 'docker info bridge' which is invalid
  • Confusing 'docker network ls' with inspect
3. Given two containers on the default bridge network, what happens if you try to ping one container by its name from the other?
medium
A. Ping fails because default bridge does not support container name resolution.
B. Ping fails unless containers are on a custom network.
C. Ping succeeds only if containers share the same image.
D. Ping succeeds because default bridge supports name resolution.

Solution

  1. Step 1: Recall default bridge network name resolution

    The default bridge network does not provide automatic DNS resolution for container names.
  2. Step 2: Understand ping behavior by name

    Trying to ping by container name will fail because the name cannot be resolved to an IP address.
  3. Final Answer:

    Ping fails because default bridge does not support container name resolution. -> Option A
  4. Quick Check:

    Default bridge name resolution = no [OK]
Hint: Default bridge lacks DNS for container names [OK]
Common Mistakes:
  • Assuming ping by name works by default
  • Confusing image sharing with network name resolution
  • Thinking custom networks are not needed
4. You created two containers on the default bridge network and tried to connect them by name, but it failed. What is the likely cause?
medium
A. The containers are not running.
B. You forgot to create a user-defined bridge network.
C. The Docker daemon is not started.
D. You used the wrong container names.

Solution

  1. Step 1: Understand default bridge limitations

    Default bridge network does not support container name resolution for communication.
  2. Step 2: Identify solution for name-based communication

    Creating a user-defined bridge network enables automatic DNS resolution of container names.
  3. Final Answer:

    You forgot to create a user-defined bridge network. -> Option B
  4. Quick Check:

    Name resolution needs user-defined bridge [OK]
Hint: Use user-defined bridge for name resolution [OK]
Common Mistakes:
  • Blaming container state without checking network
  • Assuming Docker daemon is stopped without evidence
  • Ignoring network type for name resolution
5. You want two containers to communicate by name and also access the internet. Which approach using Docker's networking should you take?
hard
A. Connect both containers to a user-defined bridge network which supports name resolution and NAT for internet access.
B. Use the default bridge network and manually edit /etc/hosts in each container.
C. Connect containers to the host network to share internet and name resolution.
D. Create a macvlan network to enable name resolution and internet access.

Solution

  1. Step 1: Identify network supporting name resolution and NAT

    User-defined bridge networks provide automatic DNS for container names and NAT for internet access.
  2. Step 2: Evaluate other options

    Default bridge lacks name resolution; host network shares host IP but no DNS; macvlan isolates containers and does not provide NAT by default.
  3. Final Answer:

    Connect both containers to a user-defined bridge network which supports name resolution and NAT for internet access. -> Option A
  4. Quick Check:

    User-defined bridge = name resolution + NAT [OK]
Hint: User-defined bridge = name resolution + internet [OK]
Common Mistakes:
  • Editing /etc/hosts manually is error-prone
  • Assuming host network provides container DNS
  • Using macvlan without NAT causes no internet
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard