Tuesday, June 13, 2017

Deploying using docker-compose file in ECS clusters

step1:

ecs-cli configure --region us-xxxxxx --access-key xxxxxxxxxxxxx   --secret-key xxxxxxxxxxxxxx --cluster xxxxxxx

Note:add this line ecscontaineragent-setupexample- to vi .ecs/config 


Step2:

There are two ways of approaches:

Method1:
ecs-cli up --keypair xxxxxxxxxxx --capability-iam --size 2 --instance-type t2.micro   --vpc vpc-xxxxxx --security-group sg-xxxxxxxx --subnets subnet-xxxxxxxx,subnet-xxxxxxxx --image-id ami-xxxxxxxxx

Note:whenever you use availability zones in the step2 ,you suppose to not use the vpc and subnet.

Note:Whenever we provide the Vpc we must have to provide more than one subnet
azs b,azs c

Method2:

ecs-cli up --keypair ecs-xxxxxx --capability-iam --size 2 --instance-type t2.micro   —azs  b,c    --image-id ami-xxxxxxx  —security-group sg-xxxxxxxxx 

(ecs-cli up --keypair ecs-xxxxxxx --capability-iam --size 2)
Help us to create an ECS cluster with two amazon ec2 instances.
(up - Creates the ECS cluster (if it does not already exist) and the AWS resources required to set up the cluster)

step:3
(test with online validator:http://www.yamllint.com/)

creating a compose file:docker-compose.yml
version: "2"
services:
  Applicationname:
    environment:
      - NODE_ENV=xxxxxxxx
    image: kaushikxxxxx/docker-applicationname
ports:
      - "hostPort:containerPort"

(OR)

Applicationname:
  image: registryaddress/docker-xxxxxxxx:latest
  cpu_shares: "10"
  environment:
   - NODE_ENV =xxxxxx
  net: bridge
  ports:
    - "hostPort:containerPort"
  mem_limit: "300"

ecscontaineragent-setupexample- replace in the config file with this in the stack name.

Step:4
deploy a compose file to cluster:

ecs-cli compose --file docker-compose.yml up

task definition  will be created for us.

Step:5

Scale up the tasks:

ecs-cli compose --file docker-compose.yml scale 2

step:6

creating an ecs-service:

a) before we create the service, we need to stop the containers by the following command:

ecs-cli compose --file docker-compose.yml  down

b)create a service:

ecs-cli compose --file docker-compose.yml  service up

c)Clean up the service:

ecs-cli compose --file docker-compose.yml  service rm


No comments:

Post a Comment