Search code examples
docker-composeamazon-ecs

ECS: Generate 2 Task Definitions from a single Docker Compose File


I have an architecture represented in this docker-compose.yml file:

version: '3'
services:
  flask:
    container_name: flask
    image: "user/demo_flask"
    ports:
      - "5000:5000"
    links:
      - mysql
  mysql:
    container_name: mysql
    image: "user/demo_mysql"
    environment:
      - MYSQL_ROOT_PASSWORD=mypassword

Here the flask service is a Flask app connecting to the mysql DB, which is just mysql:5.7 with some custom configuration. I need the services to communicate (in particular, flask has to be able to reach mysql). I want to deploy such an architecture to ECS using EC2 Launch Type. I plan to use ecs-cli to generate the Task Definitions. As long as I can understand, if I include in my directory the file ecs-params.yml :

version: 1
task_definition:
  services:
    flask:
      cpu_shares: 50
      mem_limit: 262144000
    mysql:
      cpu_shares: 50
      mem_limit: 262144000

I get a single Task Definition, which is not what I want. I would like two separate Task Definitions, each one with a single container. Is it possible to get this? Thanks.


Solution

  • One service can not be run with two task definition in ECS Cluster. What you can do here is to create two task definition (one for flask and another for mysql) and create two service using these two task definition.Now you can make communication using service discovery in ECS Cluster. Please check this aws service discovery document.