An example how to deploy a docker on AWS ECS with docker compose
What it does: Docker compose creates an ecs cluster that executes on fargate (or ec2).
Docker compose uses cloudformation to deploy, you can inspect the template both before and after a deployment.
Docker compose needs some permissions to run. You can create a role with the needed permissions with the included cloudformation script. You then have to assume role.
Use awsume to assume role, it's a handy tool to assume roles.
-
Create role for deployment
aws cloudformation deploy --template-file role.yaml --stack-name DockerComposeRole --capabilities CAPABILITY_NAMED_IAM
-
Assume role
Assume role, example use awsu.mem see prerequisites how to setup.
awsume composerole
-
Create docker context Create a docker context, select existing aws profile and select composerole (created in prerequisites)
docker context create ecs myecs
-
Deploy on ecs
docker compose up --context myecs
-
Test
It takes a while fot the ecs task to get status "running", you can monitoring the task in the ECS cluster.
To get the uri (DNS name) you have to look in the aws load balancer page, EC2 -> Load Balancing
or from the docker command:docker compose ps --context myecs
-
Remove the compose stack
docker compose down --context myecs
-
Remove docker compose role
aws cloudformation delete-stack --stack-name DockerComposeRole
-
Cleanup storage
You have to cleanup the elastic file system manually.
- Access points
- File system
-
Add assume role on your user.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "*" } ] }
-
AWS cli (to be able to deploy cloudformation)
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
-
Configurate awsu.me, add role arn in your ~/-aws/config
[profile composerole] source_profile = my-aws role_arn = arn:aws:iam::<aws account id>:role/DockerComposeRole
-
Docker (you might need the edge release)
If you tear down and setup a second time wordpress doesn't really work.
It looks like it's keeping the old url in links.
https://docs.docker.com/engine/context/ecs-integration/
https://github.com/docker/compose-cli
https://www.docker.com/blog/deploying-wordpress-to-the-cloud/
https://www.stevejgordon.co.uk/dotnet-on-aws-introducing-docker-ecs-integration
- https ?
- Autoscale
- Green/Blue deployment?