Skip to content

Commit d689a1d

Browse files
Update container networking for container-container communication
1 parent aa68ba2 commit d689a1d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

content/manuals/compose/how-tos/networking.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Within the `web` container, your connection string to `db` would look like
5959
`postgres://db:5432`, and from the host machine, the connection string would
6060
look like `postgres://{DOCKER_IP}:8001` for example `postgres://localhost:8001` if your container is running locally.
6161

62+
## Container to container communication
63+
64+
Those familiar with using `http://localhost:3000` to reference a local development URL, use `http://servicename:3000` instead when using docker compose.
65+
66+
Example: In local development you have a frontend node app running at `http://localhost:3000` which references a backend api running at `http://localhost:8080/api`. In Docker networking, you would replace the node app api reference to the backend api with `http://apiservice:8080/api`. Similarly, the frontend app would be referenced by service name `http://myapp:3000`
67+
6268
## Update containers on the network
6369

6470
If you make a configuration change to a service and run `docker compose up` to update it, the old container is removed and the new one joins the network under a different IP address but the same name. Running containers can look up that name and connect to the new address, but the old address stops working.
@@ -178,7 +184,7 @@ networks:
178184

179185
Instead of attempting to create a network called `[projectname]_default`, Compose looks for a network called `my-pre-existing-network` and connects your app's containers to it.
180186

181-
## Further reference information
187+
## Further reference information
182188

183189
For full details of the network configuration options available, see the following references:
184190

content/manuals/engine/network/drivers/bridge.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ network.**
3737

3838
- **User-defined bridges provide automatic DNS resolution between containers**.
3939

40+
> **See also**: Learn how to communicate between containers by name (containername:port instead of localhost:port) in: [Container to container communication in Docker Compose](/manuals/compose/how-tos/networking.md#container-to-container-communication).
41+
4042
Containers on the default bridge network can only access each other by IP
4143
addresses, unless you use the [`--link` option](../links.md), which is
4244
considered legacy. On a user-defined bridge network, containers can resolve

0 commit comments

Comments
 (0)