Deploy a WordPress site on Amazon ECS

Containers seem to be everywhere these days, so I decided to jump on the bandwagon. Below is a step-by-step guide on how to quickly get started with Amazon ECS. Most of the commands were taken straight from the ECS-CLI tutorial found here.

Setup the CLI

ecs-cli installation instructions

On a Mac

sudo curl -o /usr/local/bin/ecs-cli

On Linux

sudo curl -o /usr/local/bin/ecs-cli

Chmod permissions

sudo chmod +x /usr/local/bin/ecs-cli

Follow the steps described here to configure the ecs-cli. If you have already setup the AWS CLI, the configuration steps are simplified: just run ecs-cli configure –profile yourprofilename

Working with the cluster

Create your cluster

You need to create the keypair beforehand. You can run the following command to create it: aws ec2 create-key-pair –key-name id_rsa Make sure that the value after –port matches your compose file’s port number.

ecs-cli up --keypair id_rsa --capability-iam --size 1 --instance-type t2.micro --port 11111

Create Docker compose file

version: '2'
    image: wordpress
    cpu_shares: 100
    mem_limit: 524288000
      - "80:80"
      - mysql
    image: mysql
    cpu_shares: 100
    mem_limit: 524288000
      MYSQL_ROOT_PASSWORD: password

Deploy compose file

ecs-cli compose up --file hello-world.yml 

View cluster

ecs-cli ps

Scale up to 2 tasks

ecs-cli compose --file hello-world.yml scale 2

Shut down tasks

ecs-cli compose --file hello-world.yml down

Create ECS service

ecs-cli compose --file hello-world.yml service up


Remove tasks

ecs-cli compose --file hello-world.yml service rm

Remove resources (actual EC2 instances)

ecs-cli down --force
comments powered by Disqus