Skip to content

Commit 3c856e9

Browse files
authored
Update networking.mdx for networks
1 parent f392b4e commit 3c856e9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

docs/concepts/networking.mdx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This page is about internal networking only. If you want to configure your servi
1616

1717
## Internal Communication
1818

19-
You can expose ports in your service definition to allow other services to communicate with it. Similar to public communication, you can use the `ports` section of your service definition, but set the `mode` to `host` instead of `ingress` to allow other services to communicate with it through the internal network.
19+
You can expose ports in your service definition to allow other services to communicate with it. Similar to public communication, you can use the `ports` section of your service definition. Set the `mode` to `host` (instead of the default `ingress`) to be able to connect to the container directly, avoiding the need of a load balancer.
2020

2121
### Sample Configuration
2222

@@ -66,3 +66,35 @@ http://<service-name>:<port>
6666
```
6767
</TabItem>
6868
</Tabs>
69+
70+
### Networks
71+
72+
The Compose spec has a notion of [networks](https://github.com/compose-spec/compose-spec/blob/main/06-networks.md). By default, each service gets added to the `default` network. Networks in Compose can be flagged as `internal`, but this means they have no connection to the outside world at all (no egress).
73+
74+
Only services in the `default` network can have public IPs. Services in any other network will be in a private subnet.
75+
76+
```yaml
77+
services:
78+
frontend:
79+
build: ./fe
80+
ports:
81+
- 80 # load-balanced, ie. mode: ingress
82+
networks:
83+
default:
84+
private:
85+
86+
backend:
87+
build: ./be
88+
ports:
89+
- mode: host # no load balancer
90+
target: 8080
91+
networks:
92+
private:
93+
94+
networks:
95+
default:
96+
private:
97+
internal: true # no egress
98+
```
99+
100+

0 commit comments

Comments
 (0)