I scale container
ports:
- "8086-8090:8085"
But what if I needed it only inside my bridge network? In other words, does it exists something like this?
expose:
- "8086-8090:8085"
UPDATED: I have a master container:
- exposed to host network
- acts as a load balancer
I want to have N slaves of another container, exposed to assigned ports inside docker network (bot visible in host network)
CodePudding user response:
Connections between containers (over the Docker-internal bridge network) don't need ports:
at all, and you can just remove that block. You only need ports:
to accept connections from outside of Docker. If the process inside the container is listening on port 8085 then connections between containers will always use port 8085, regardless of what ports:
mappings you have or if there is one at all.
expose:
in a Compose file does almost nothing at all. You never need to include it, and it's always safe to delete it.
(This wasn't the case in first-generation Docker networking. However, Compose files v2 and v3 always provide what the Docker documentation otherwise calls a "user-defined bridge network", that doesn't use "exposed ports" in any way. I'm not totally clear why the archaic expose:
and links:
options were kept.)
CodePudding user response:
No extra changes needed!
Because of internal Docker DNS it 'hides' scaled instances under same port:
version : "3.8"
services:
web:
image: "nginx:latest"
ports:
- "8080:8080"
then
docker-compose up -d --scale web=3
calling localhost:8080 will proxy requests to all instances using Round Robin!