Deploy your containers to AWS or Azure in under 10 minutes (no, really!)
Tags: docker, aws, azure, cloud
Published: 2021-05-28 12:57:16

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

## Create context

To manage our cloud deployments we'll have to set up a new [docker context](https://docs.docker.com/engine/context/working-with-contexts/).

### Using AWS

    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](https://docs.docker.com/cloud/ecs-integration/#requirements).

    ? Create a Docker context using:  [Use arrows to move, type to filter]
    > An existing AWS profile
    AWS secret and token credentials
    AWS environment variables

### Using Azure

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 `--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

## 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](https://docs.docker.com/cloud/ecs-integration/) and [Azure](https://docs.docker.com/cloud/aci-integration/) deployment. But that will probably take more than 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 <a href="https://unsplash.com/@pericakalimerica?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Pero Kalimero</a> and <a href="https://unsplash.com/@toddcravens?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Todd Cravens</a> on <a href="https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>_