Below is a simplified version of my docker-compose.yml file.

I can understand or find any resources to tell me which container of the 5 django replicas the nginx container will target if i reference it.

For example, as you can see if my compose file I have one instance of Nginx and five of Django.

If my nginx config i have an upstream like this:

upstream docking_django {
    server web:3000;

Which web container will the upstream come from? Will it load balance between them? I'm deploying to AWS ECS and when I try running it, it seems like it's load balancing somehow. But I would like to understand it further since it doesn't seem to behave the same way always.

version: '3.9'

    image: .dkr.ecr.eu-west-3.amazonaws.com/tin-api-v2/django:${IMAGE_TAG}
      context: .
      dockerfile: ./Dockerfile
      - demoapp
      replicas: 5

    image: .dkr.ecr.eu-west-3.amazonaws.com/tin-api-v2/nginx:${IMAGE_TAG}
      context: .
      dockerfile: ./nginx.Dockerfile
      - 80:80
      - web
      - demoapp
      replicas: 1


Yes Felix. Loosely speaking it "load balance" across your 5 web container instances. If you are using the ECS / Compose integration and you are bringing up this stack with a compose up this is roughly what happens:

  • it creates an ECS cluster
  • it creates task def for the web task and the nginx task
  • it creates a service for web (with 5 tasks in it)
  • it creates a service for nginx (with 1 task in it)
  • it exposes the nginx service via an ALB to the public (because you expose the port 80)
  • it creates an internal mechanism based on ECS Service Discovery to be able to resolve web inside the cluster (that's how the nginx is able to reach an entity called web).

ECS SD leverages CloudMap/Route53 which will round-robin across the 5 entries (web tasks). You can read more here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.