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