Load balancing/routing between replicas

I have the following docker setup:

Web --> traefik --> frontend/api --> backend

I have a docker-compose.yml that configures frontend/api and backend. The frontend has a http connection to the backend, by calling it with its container name http://backend:8080/.

Now I want to scale the frontend and backend in parallel (2 frontends and 2 backends).

So I start it with:

docker-compose up -d --scale frontend=2 --scale backend=2

The traefik does the load balancing for the frontend. But now I can’t user container names to route from the frontend to the backend anymore.

How can I organize the routing between scaled containers with pure docker and docker-compose. (No swarm or kubernetes.)

Note:
A solution to scale only the backend but access all replicas round robin under the same hostname from the frontend might be half way of a solution already.

Source: Docker Questions

LEAVE A COMMENT