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: jq on docker network inspect lists each container's address

Jq
~/tips/tip-jq-docker-network-subnets

docker network inspect $(docker network ls -q) \

See which subnet a Docker network uses and which address each container got.

When two Docker networks clash with your LAN or a container can’t reach another one, I want the subnets and addresses at a glance. docker network inspect has them, buried in JSON, and jq digs them out.

docker network inspect bridge | jq -r '.[0].IPAM.Config[].Subnet'

docker network inspect bridge \
  | jq -r '.[0].Containers[] | [.Name, .IPv4Address] | @tsv'

docker network inspect $(docker network ls -q) \
  | jq -r '.[] | [.Name, (.IPAM.Config[0].Subnet // "-")] | @tsv'

The first command prints the subnet of the default bridge network. The second lists every container attached to it with its address and prefix. The third goes over all networks at once and prints name and subnet side by side, which is the one I’d use when you suspect an overlap with a VPN or home network range.

inspect always returns an array, even for one network, hence the .[0] and .[]. Containers is an object keyed by container ID, and .[] on an object loops over its values, so you don’t need the IDs.

Only running containers show up under Containers. A stopped one has no address, so if a container is missing from the list, check docker ps -a. The // "-" fallback is there because the host and none networks have no subnet. Containers on the host network don’t get their own address at all.

Further reading: docker network inspect, jq manual

More Jq tips jq -r '.files[] | @sh' data.json jq -n -c 'limit(3; range(1; 1000000000))' jq -n -c '$ARGS.positional' --args a "b c" jq 'with_entries(.key |= ascii_upcase)' jq '.replicas |= . + 1' deploy.json All Jq tips (20) All topics

Link