Did you know you can deploy your existing docker-compose stack to AWS Elastic Container Service or Azure Container Instance using the docker command? Yeah, me neither.
There is a tech preview of the docker CLI that includes the
compose command. This is mostly compatible with the earlier
The tech preview is included in Docker Desktop for Mac and Windows 3.2.1 and above, but if you want to run it on Linux you'll have to install it yourself:
# Docker CLI tech preview linux install curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh
To manage our cloud deployments we'll have to set up a new docker context.
docker context create ecs some-name-here
You can use your AWS credentials in one of three ways. If you alreade have the AWS CLI configured, you can use your credentials from there. Otherwise you can input them when asked or use environment variables. Make sure your IAM role has the correct premissions.
? Create a Docker context using: [Use arrows to move, type to filter] > An existing AWS profile AWS secret and token credentials AWS environment variables
The procedure for Azure is a little bit different. You must first tell docker to log in to Azure:
docker login azure
This will open a web page where you enter your credentials, or fall back to using the Azure device code flow. Note that this is separate from the Azure CLI login.
This can be done without interaction as well, which is handy for CI workflows:
docker login azure --client-id xx --client-secret yy --tenant-id zz
You can use the
--tenant-id option alone to specify a tenant, if you have multiple ones.
To create the actual docker context we run:
docker context create aci some-name-here
This command will let you pick a resource group to use, or create a new one. Again, to run this without interaction we can specify
Once your context is created you can view it by running
docker context ls.
To activate the context run:
docker context use some-name-here
Now that we have the basics covered, we are ready to deploy stuff!
It is almost too simple, just run
docker compose up as you normally would. Docker will automagically create all necessary resources in AWS or Azure and deploy your container(s). Similarly,
docker compose down will remove everything.
Fret not! The Docker CLI has support for many more things, such as volumes, secrets, auto scaling, DNS labels, health checks and so on...
Jonathan Walter is a Media Consultant at Eyevinn Tecnology, the European leading independent consultancy firm specializing in video technology and media distribution.