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 connect adds a running container to a second network

Docker
~/tips/tip-docker-network-connect

docker network connect proxy-net app

Attaches an existing container to another Docker network without recreating it.

A typical self-hosting setup has a reverse proxy on one Docker network and each app on its own. Sometimes an app needs to be on both, and you do not want to recreate it just to test that.

docker network connect proxy-net app

That attaches the running container app to the network proxy-net. It keeps its existing networks, so now it can talk to both sides.

You can give it an extra name on that network with --alias. The Docker docs show more than one alias at once:

docker network connect --alias db --alias mysql backend-net mariadb

Other containers on backend-net can now reach it as db or mysql. And to undo it:

docker network disconnect proxy-net app

The docs say the container must be running to disconnect it; -f forces it.

Caveat: this is a change to a running container, not to your compose file. On the next docker compose up that recreates the container, the extra network is gone again. I’d use the command to try something out, and put the network in the compose file once it works. The docs also warn that if you gave the container a fixed IP on a network and that address is taken when it restarts, the container fails to start.

Further reading: docker network connect reference, docker network disconnect reference

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