3
votes

I have created a Docker containers using docker-compose. In my local environment, i am able to bring up my application without any issues.

Now i wanted to deploy all my docker containers to the AWS EC2 (ECS). After going over the ECS documentation, i found out that we can make use of the same docker-compose to deploy in ECS using ECS-CLI. But ECS-CLI is not available for windows instances as of now. So now i am not sure how to use my docker-compose to build all my images using a single command and deploy it to the ECS from an windows instance.

It seems like i have to deploy my docker containers one by one to ECS as like below steps,

  1. From the ECS Control Panel, create a Docker Image Repository.
  2. Connect your local Docker client with your Docker credentials in ECS:
  3. Copy and paste the Docker login command from the previous step. This will log you in for 24 hours
  4. Tag your image locally ready to push to your ECS repository – use the repo URI from the first step
  5. Push the image to your ECS repoository\
  6. create tasks with the web UI, or manually as a JSON file
  7. create a cluster, using the web UI.
  8. Run your task specifying the EC2 cluster to run on

Is there any other way of running the docker containers in ECS ?

2
Just start an Ubuntu EC2 instance, install ecs-cli there, deploy your services with your docker-compose file using ecs-cli. When successfully deployed, terminate Ubuntu EC2 instance. - Rafaf Tahsin

2 Answers

2
votes

Docker-Compose is wrong at this place, when you're using ECS.

You can configure multiple containers within a task definition, as seen here in the CloudFormation docs:

ContainerDefinitions is a property of the AWS::ECS::TaskDefinition resource that describes the configuration of an Amazon EC2 Container Service (Amazon ECS) container

Type: "AWS::ECS::TaskDefinition"
Properties: 
  Volumes:
    - Volume Definition
  Family: String
  NetworkMode: String
  PlacementConstraints:
   - TaskDefinitionPlacementConstraint
  TaskRoleArn: String
  ContainerDefinitions:
    - Container Definition

Just list multiple containers there and all will be launched together on the same machine.

1
votes

I got the same situation as you. One way to resolve this was using the Terraform to deploy our containers as a Task Definitions on AWS ECS.

So, we using the docker-compose.yml to run locally and the terraform is a kind of mirror of our docker-compose on AWS.

Also another option is Kubernetes that you can translate from docker-compose to Kubernetes resources.