brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker network inspect shows which containers are on a network

Docker
~/tips/tip-docker-network-inspect-containers-ips

docker network inspect bridge

Prints the subnet, gateway and attached containers of a Docker network, and --format picks out single fields.

When two containers cannot reach each other, I first want to know which network each one is on. The network itself can tell me.

docker network ls
docker network inspect bridge

The output is JSON with the driver, the subnet and gateway under IPAM, and a Containers section that lists the attached containers with their IP and MAC addresses. If a container is not listed on the network where you expected it, you found your problem.

The JSON is long, so --format with a Go template extracts what you need:

docker network inspect bridge --format '{{range .Containers}}{{.Name}} {{.IPv4Address}}{{println}}{{end}}'

That prints one line per container with its name and address. For a Compose project, the network name is usually the project name followed by _default, which docker network ls shows.

The caveat is that the list describes the current situation. Containers that are stopped usually do not appear in it, so an empty list does not mean nothing was ever attached. Also, containers on the default bridge network cannot find each other by name. Only user-defined networks provide that, so check which kind of network you are looking at before debugging DNS.

Further reading: docker network inspect

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link