I have two containerised services, A and B, with which I wish to isolate network communications with docker compose. There is also a shared service C which is not isolated from A or B and is free to communicate with either.
I have tried to achieve this with the following docker-compose.yaml:
version: "3.3"
services:
C:
build: C
depends_on:
- A
- B
expose:
- 8080
networks:
- A
- B
A:
build: A
expose:
- 8080
networks:
- A
B:
build: B
expose:
- 8080
networks:
- B
networks:
A:
internal: true
B:
internal: true
With this, C is able to connect to both A and B on the hosts A:8080 and B:8080 respectively and A and B are isolated as required. However, neither A nor B is able to connect to C on C:8080. Removing the network options from the compose file, all services are able to talk to each other. What am I doing wrong?