docker run -d--name web-api --network app-net myapp:1.0docker run -d--name db --network app-net postgres:16
Note Containers on the same user-defined network can reach each other by container name (e.g., web-api can connect to db:5432). The default bridge network does NOT provide this DNS - you must create a custom network.
Note A container can be connected to multiple networks simultaneously. This is useful for gateway containers that need to communicate with two isolated groups of services.
Frequently asked questions
How do you join network?
Docker covers this with 2 copy-ready snippets on this page. The "Specify Network (--network)" snippet in Docker uses `docker run --network <network_name> <image>`.
Which command does the Docker example use?
The "Specify Network (--network)" snippet uses `docker run --network <network_name> <image>`, from the Run Options section of the Docker cheat sheet.
What other Docker snippets are shown for "join network"?
Besides "Specify Network (--network)", this page also shows "Connect & Disconnect Containers".
Is there anything to watch out for?
Yes. For "Specify Network (--network)": Containers on the same user-defined network can reach each other by container name (e.g., web-api can connect to db:5432). The default bridge network does NOT provide this DNS - you must create a custom network.