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 run --network container: puts a debug toolbox inside another container's network

Docker
~/tips/tip-docker-run-network-container-netshoot

docker run --rm -it --network container:sonarr nicolaka/netshoot

Runs a throwaway toolbox container that shares the network of a container you want to debug.

Most images I run on my Unraid server are stripped down so far that there’s no curl, no dig and sometimes not even a shell. That’s good for security and terrible when a container can’t reach its database and you want to know why. Docker has a neat answer for this: start a second container that shares the network stack of the broken one.

The flag is --network container:<name>. The new container gets no network of its own. It sees the same interfaces, the same IP address, the same /etc/resolv.conf and the same localhost as the container you point it at. Pair it with nicolaka/netshoot, an image packed with network tools, and you have a toolbox inside the problem:

docker run --rm -it --network container:sonarr nicolaka/netshoot

From that shell you’re looking at the network exactly as Sonarr sees it. For example, to check whether the name of your download client resolves and whether its port answers:

dig sabnzbd
curl -sI http://sabnzbd:8080
ss -tulnp

The last command lists the ports the app itself listens on, which is handy when a web UI only binds to 127.0.0.1 inside the container. Because you share that loopback, curl http://127.0.0.1:8989 works from netshoot too. The --rm throws the debug container away when you type exit, and the original container isn’t touched at all.

One caveat: in this mode a few flags are off limits, because the network belongs to the other container. The Docker docs list --publish, --hostname, --dns and --add-host among them. The debug container also has root and a pile of tools inside the network of a running app, so close it when you’re done instead of leaving it around. My advice is to pin netshoot to a version or digest if you keep it around, like any other image you pull from Docker Hub.

Further reading: Docker networking: container networks, netshoot on GitHub

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