Deploy Django App with Docker Compose Context to AWS ECS

0

I built my docker Django app with Django-cookiecutter ( It makes a bootstrap application that is ready for production). The application works fine on my local machine with no errors. I pushed the production images to AWS ECR and used docker context ecs to deploy the application. The problem I am facing is that it starts creating all the instances and after a while starts deleting them again. I can't figure out where the problem is coming from. I am a beginner in this and I will appreciate any assistance. This is what my YAML file looks like.

version: '3'

volumes:
  production_postgres_data: {}
  production_postgres_data_backups: {}
  production_traefik: {}

services:
  django: &django
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    image: public.ecr.aws/t6g1j7b6/image_converter:django
    platform: linux/x86_64
    depends_on:
      - postgres
      - redis
    env_file:
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
    command: /start
    networks:
      - proxy
      - default


  postgres:
    build:
      context: .
      dockerfile: ./compose/production/postgres/Dockerfile
    image: public.ecr.aws/t6g1j7b6/image_converter:postgres
    volumes:
      - production_postgres_data:/var/lib/postgresql/data:Z
      - production_postgres_data_backups:/backups:z
    env_file:
      - ./.envs/.production/.postgres

  traefik:
    build:
      context: .
      dockerfile: ./compose/production/traefik/Dockerfile
    image: public.ecr.aws/t6g1j7b6/image_converter:traefik
    depends_on:
      - django
    volumes:
      - production_traefik:/etc/traefik/acme
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"
      - "0.0.0.0:5555:5555"

  redis:
    image: public.ecr.aws/t6g1j7b6/image_converter:redis

  celeryworker:
    <<: *django
    image: public.ecr.aws/t6g1j7b6/image_converter:celeryworker
    command: /start-celeryworker


  celerybeat:
    <<: *django
    image: public.ecr.aws/t6g1j7b6/image_converter:celerybeat
    command: /start-celerybeat

  flower:
    <<: *django
    image: public.ecr.aws/t6g1j7b6/image_converter:flower
    command: /start-flower

networks:
  proxy:

  • Is there any indication on CloudWatch in relation to ECS service, cluster and similar? Also double check the health check on ec2

已提问 1 年前815 查看次数
1 回答
0
已接受的回答

Hi there,

I just completed a django app deployed as well. I noticed a few things on your file:

  1. Maybe we don't need to build an image for postgre database because you can set up an RDS or EBS to connect to your django app.
  2. There should be "links" betweeb the reverse proxy (traefik) and the django.
  3. For redis, celery, celery worker, flower I don't think we need a separate image for each. They are part of the code in your django app, if we build a proper image for the django app, these are already included.

I am newbie too, would love to hear your feedback. Good luck, you will make it!

profile picture
cloud9
已回答 1 年前
profile picture
专家
已审核 1 个月前
  • What I did was remove the redis, celerybeat, celeryworker and flower images that you suggested but left the rest the way it was and it worked. A gazillion thanks.

  • Hey, glad that it worked out for you, do you know why you have to build an image for postgre?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则