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

preguntada hace 2 años992 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
respondido hace 2 años
profile picture
EXPERTO
revisado hace 4 meses
profile picture
EXPERTO
revisado hace 7 meses
  • 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?

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas