DEV Community

loading...
Cover image for Deploy your containers to AWS or Azure in under 10 minutes (no, really!)
Eyevinn Video Dev-Team Blog

Deploy your containers to AWS or Azure in under 10 minutes (no, really!)

Jonathan Walter
・3 min read

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.

Get the CLI

There is a tech preview of the docker CLI that includes the compose command. This is mostly compatible with the earlier docker-compose.

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
Enter fullscreen mode Exit fullscreen mode

Create context

To manage our cloud deployments we'll have to set up a new docker context.

Using AWS

docker context create ecs some-name-here
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Using Azure

The procedure for Azure is a little bit different. You must first tell docker to log in to Azure:

docker login azure
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 --subscription-id, --resource-group, and --location.

Activate your context

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
Enter fullscreen mode Exit fullscreen mode




Deploy your stack

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.

But I want to do more advanced things!

Fret not! The Docker CLI has support for many more things, such as volumes, secrets, auto scaling, DNS labels, health checks and so on...

I highly recommend you read the official documentation/guides for AWS and Azure deployment. But that will probably take more that 10 minutes.


Jonathan Walter is a Media Consultant at Eyevinn Tecnology, the European leading independent consultancy firm specializing in video technology and media distribution.

Image is a montage of photos by Pero Kalimero and Todd Cravens on Unsplash

Discussion (0)