[Answered ]-Docker configuration for Django+Vuejs+Gunicorn+Nginx lead to 502 Bad Gateway

1👍

You do not want to run everything into a single container. A container should be doing just one thing. You have a couple of options. Run one container per module (nginx, app, etc) and group them into a single ECS task. The task is a deployment and scaling unit in ECS that you can control with an ECS service. So you could have 1 ECS service per customer and start with 1 task backing it. If you need more "power" ECS will scale your single task to 2 tasks (doubling all your containers). And so on.

The second approach (architecturally better but perhaps more expensive) is to have a task per each container and so a total of 3 independent tasks wrapped in 3 independent services. Each service then can scale on its own (e.g. if you need more capacity for NGINX only the NGINX task will be scaled in the NGINX ECS service. If you adopt this approach you will need to have 3 services (plus the db) per customer.

This is a demo application I am using for these experiments that kind of mimics your app. My docker-compose file for this application looks like this:

version: "3.0"
services:
  yelb-ui:
    image: mreferre/yelb-ui:0.7
    depends_on:
      - yelb-appserver
    ports:
      - 80:80
    networks:
      - yelb-network

  yelb-appserver:
    image: mreferre/yelb-appserver:0.5
    depends_on:
      - redis-server
      - yelb-db
    networks:
      - yelb-network

  redis-server:
    image: redis:4.0.2
    networks:
      - yelb-network
    # uncomment the following lines if you want to persist redis data across deployments
    #volumes:
    # - redisdata:/data

  yelb-db:
    image: mreferre/yelb-db:0.5
    networks:
      - yelb-network
    # uncomment the following lines if you want to persist postgres data across deployments
    #volumes:
    #  - postgresqldata:/var/lib/postgresql/data

networks:
  yelb-network:
    driver: bridge # a user defined bridge is required; the default bridge network doesn't support name resolution

That’s how your application will run locally. If you want to run it on ECS you can either use a tool like Copilot or, if you want to stick using docker compose you could leverage the new docker compose integration with ECS and docker compose up your app into ECS directly.

Both of these solutions will implement the second pattern I have described (1 container per task). If you want the "all containers in a task" pattern you should craft a native CloudFormation template.

Leave a comment