Docker has been busy at work, extending the Docker compose functionality. What's new this week is the ability to deploy docker containers directly to Amazon AWS ECS using the standard Docker commands.
A flurry of development has occurred since the release of the compose specification. Microsoft Azure integrated compose with their Azure Container Instances (ACI) and now Amazon with AWS ECS.
The new compose specification allows developers to develop locally and then switch context to AWS and deploy the same application directly to AWS ECS using all your existing local development tools and workflows.
The integration between Docker and Amazon AWS ECS allows developers to use the Docker CLI to:
Before getting started, we need to ensure a couple of things are in place.
Ensure you have the latest Docker edge release containing the ECS functionalityEnsure you have an AWS accounthttps://aws.amazon.com/cli/https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.htmlhttps://docs.aws.amazon.com/AmazonECS/latest/userguide/create_cluster.html
Once we complete the prerequisites, we can continue with the setup of Docker with ECS. Docker has a built-in setup tool, surprisingly called docker ecs setup
How easy is that?
Open a Terminal window (Powershell or Linux shell)docker ecs setup
Answer the questions prompted on the screen
Enter Credentials: Step 3 of the prerequisites insert your access keys here
to view your available contexts.
I've created a demo repo using my favorite cat Gif generator Python application.
123456.dkr.ecr.eu-central-1.amazonaws.com/brian-test/docker-ecs-demo
First, edit the docker-compose.yml
file
/docker-ecs-demo``docker-compose.yml
file
Should look like
version: '3.4' services: pythonproject: image: 123456.dkr.ecr.eu-central-1.amazonaws.com/brian-test/docker-ecs-demo build: context: . dockerfile: Dockerfile ports: - 80:5000
to provide a unique name to our stack
This command will then run for a couple of minutes as AWS will create the ECS service & task, Security Groups, Logging, Loadbalancers, Roles, networks, and more.. Here you will find the deployment of our Cat application``EC2 -> Load Balancers
at the end of the DNS name
Here's the Cat Application running in the 56K.Cloud account. Every time you refresh the webpage, you find a new Cat GIF. Endless entertainment and the true use of the internet, cat GIFs.
Live Demo - http://pythondemoloadbalancer-8271419734bafe24.elb.eu-central-1.amazonaws.com:5000/
Docker ECS integration automatically configures authorization so you can pull private images from Amazon ECR registry on the same AWS account. If you want to use another registry, including Docker Hub, you’ll have to create a Username + Password (or Username + Token) secret on Amazon SMS service.
The Docker ECS integration also offers the possibility to use secrets. The docker ecs secret
command allows you to manage secrets created on AWS SMS without having to install the AWS CLI.
docker ecs secret create dockerhubAccessToken --username <dockerhubuser> --password <dockerhubtoken>
arn:aws:secretsmanager:eu-west-3:12345:secret:DockerHubAccessToken
Once created, you can use this ARN in your Compose file using using x-aws-pull_credentials
custom extension aside the Docker image URI for your service
version: 3.8 services: worker: image: mycompany/privateimage x-aws-pull_credentials: "arn:aws:secretsmanager:eu-west-3:12345:secret:DockerHubAccessToken"
If you set Compose file version 3.8 or later, you can use the same Compose file for local deployment using docker-compose. Custom extension will be ignored.
Since Docker ECS is freshly available on the Edge channel we recommend testing and providing feedback. If you find any issues please report them directly on the Docker ECS repo.
We love Cloud, IoT, Containers, DevOps, and Infrastructure as Code. If you are interested in chatting connect with us on Twitter or drop us an email: info@56K.Cloud. We hope you found this article helpful. If there is anything you would like to contribute or you have questions, please let us know!
Software Engineer
"Brian Christner hails from Arizona but now resides in the Alps of Switzerland. Brian is a nominated member of the Docker Captain’s program and specializes in converting coffee into containers."