Scenario
Ops ticket: “Stand up an isolated Docker network for app containers. Create a user-defined bridge network, attach two containers, and verify they can resolve each other by name. Then clean up everything.”
User-defined bridge networks provide built-in DNS for container name resolution. This is the preferred pattern for multi-container apps that need predictable connectivity without hardcoding IP addresses.
Objective
- List existing Docker networks.
- Create a user-defined bridge network named
appnet. - Run two containers (
app1,app2) attached toappnet. - Verify containers are running.
- Verify name resolution and connectivity by pinging
app2fromapp1. - Capture evidence using
docker network inspect. - Remove containers and delete the network.
Concepts
- Docker networks define how containers connect and communicate.
- User-defined bridge networks include automatic DNS-based name resolution for containers on the same network.
- Container names become resolvable hostnames within the network scope.
-
docker network inspectis your evidence tool for showing attached containers, IP assignments, and network configuration. - Cleanup is part of the ticket: remove containers first, then remove the network.
Walkthrough
docker network ls
This is your baseline. It proves current state and helps you confirm the default networks exist before creating anything new.
NETWORK ID NAME DRIVER SCOPE
a1b2c3d4e5f6 bridge bridge local
b2c3d4e5f6a1 host host local
c3d4e5f6a1b2 none null local
appnet.
docker network create appnet
User-defined bridge networks are the standard approach for multi-container connectivity because they provide scoped DNS and predictable service discovery by name.
7aa1bb2cc3dd4ee5ff6677889900aabbccddeeff0011223344556677889900
docker network ls
Confirm the new network appears in the list. This is your proof that creation succeeded before you attach workloads.
NETWORK ID NAME DRIVER SCOPE
a1b2c3d4e5f6 bridge bridge local
b2c3d4e5f6a1 host host local
c3d4e5f6a1b2 none null local
d4e5f6a1b2c3 appnet bridge local
appnet.
docker run -d --name app1 --network appnet alpine:latest sleep 1d
docker run -d --name app2 --network appnet alpine:latest sleep 1d
These containers are intentionally minimal and long-running.
Using sleep 1d keeps them alive so you can test
name resolution and connectivity.
# Example container IDs:
111122223333444455556666777788889999aaaabbbbccccddddeeeeffff0000
0000ffffeeeeddddccccbbbbaaaa999988887777666655554444333322221111
docker ps
Confirm both containers are up before testing network connectivity.
CONTAINER ID IMAGE COMMAND STATUS NAMES
111122223333 alpine:latest "sleep 1d" Up 3 seconds app1
0000ffffeeee alpine:latest "sleep 1d" Up 1 seconds app2
app1, ping app2 by name.
docker exec -it app1 ping -c 3 app2
This is the key test. Success proves that user-defined network DNS is working and the containers can reach each other within the bridge network.
PING app2 (172.19.0.3): 56 data bytes
64 bytes from 172.19.0.3: seq=0 ttl=64 time=0.12 ms
64 bytes from 172.19.0.3: seq=1 ttl=64 time=0.10 ms
64 bytes from 172.19.0.3: seq=2 ttl=64 time=0.11 ms
--- app2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
appnet for ticket evidence.
docker network inspect appnet
This shows network properties and attached containers. In real ops work, this is the screenshot or copy-paste proof you include back into the ticket.
[
{
"Name": "appnet",
"Driver": "bridge",
"Containers": {
"111122223333...": { "Name": "app1" },
"0000ffffeeee...": { "Name": "app2" }
}
}
]
docker rm -f app1 app2
Remove containers first. Networks cannot be removed while containers are attached.
app1
app2
docker network rm appnet
This returns the system to baseline and closes out the ticket requirement for full cleanup.
appnet
Common breakpoints
The name may already exist or the daemon may be unhealthy. Verify Docker is running and confirm the network name is not in use.
Containers may not be attached to the same user-defined
network. Confirm both are on appnet and retry.
One or more containers are still attached. Remove containers (or disconnect them) before removing the network.
Cleanup checklist
This lab includes cleanup as part of the workflow. Confirm the containers are removed and the network no longer exists.
docker ps
docker network ls | grep appnet || true
app1 and app2 are gone, and
appnet no longer appears in docker network ls.
Reference
-
docker network ls: List Docker networks. -
docker network create <name>: Create a user-defined network. -
docker run -d --name <name> --network <net> <image> <cmd>: Start a container attached to a specific network. -
docker ps: List running containers. -
docker exec -it <container> ping -c <n> <name>: Test name resolution and connectivity from inside a container. -
docker network inspect <name>: Show network configuration and attached containers. -
docker rm -f <container...>: Stop and remove one or more containers.-
-f: Force stop then remove.
-
-
docker network rm <name>: Remove a Docker network.