...
While it is quite possible to run the application directly in EC2 Instances we then become responsible for maintaining the images and some elements of the deployment will become AWS specific. By using Docker containers we are able to run the same builds both locally on dev machines and on different cloud hosts using the same configurations.
Architecture
For MVP testing we will use a simple architecture of 1 or more EC2 Instances in a ECS Cluster. Each running the docker image that has been stored in the ECR registry.
Build the cluster
We use the ecs-cli command line tool to create a cluster of the right sized instances.
Code Block |
---|
language | bash |
---|
title | aws/createcluster |
---|
|
ecs-cli up --keypair vly1 --capability-iam --size 1 --instance-type t2.small --cluster-config default -f |
Build the docker image
Code Block |
---|
language | bash |
---|
title | aws/buildimage |
---|
|
# Get a docker login and run it
$(aws ecr get-login --no-include-email --region ap-southeast-1)
# build the docker image
docker build -t vly1-main-repo .
# tag the image
docker tag vly1-main-repo:latest 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest
# push to the repository
docker push 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest
|
Start the Services
Code Block |
---|
language | bash |
---|
title | aws/service |
---|
|
# aws/service up
# aws/service down
ecs-cli compose --verbose --file docker-compose-ecs-atlas.yml service $1
|
Find out what we have
Code Block |
---|
# Lists all of the running containers in your ECS cluster
ecs-cli ps
[~/workspace/voluntarily/vly1] $ ecs-cli ps
Name State Ports TaskDefinition Health
0c9c22ab-2019-4cde-8644-129343378bb7/web RUNNING 13.229.238.124:80->8000/tcp vly1:12 UNKNOWN |
Scale the number of servers
Code Block |
---|
# example scale to 3 servers.
ecs-cli scale --capability-iam --size 3
# note that you can force reload of the image by scaling to zero and back up again without stopping the service. |