0

I want to deploy an application using docker-compose inside an EC2 host.

For reasons beyond the scope of this question, one of the services will use a constant docker tag, as in myrepo/myimage:stable.

Periodically, the image will be updated (same tag, different hash) so I will need to run docker-compose pull && docker-compose up -d.

My question is whether there is a way of exposing docker-compose's API so that this can be invoked using an api call to the EC2 instance so as to avoid having to ssh into the machine.

pkaramol
  • 16,451
  • 43
  • 149
  • 324

1 Answers1

0

Compose doesn't have an API per se, it is just a local command-line tool. You need to use something like ssh, or a generic system-automation tool like Ansible or Salt Stack, to invoke it.

Amazon's hosted container-cluster systems do have network-accessible APIs. If you use EKS, you can use the Kubernetes API to update a Deployment spec's image:. Amazon's proprietary ECS system has a different API, but again you can use it to remotely update the image name without having direct access to the underlying node(s).


In all cases you will be better off if you can use a unique tag per build. In a Compose setup you could supply this via an environment variable

image: myrepo/myimage:${TAG:-stable}

and then deploy it with

ssh root@remote-host TAG=20210414 docker-compose up -d

Since each build would have a distinct tag/name, you don't need to explicitly docker-compose pull; Docker will know to pull an image that it doesn't already have locally.

In a Kubernetes/EKS context in particular, it's important that the image: value changes to force an update (or downgrade!); if you tell Kubernetes that you want to run a Pod with the stable tag, and it already has one, it won't change anything.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Thanks; even in the case of distinct tags however I do have to update (somehow) my `docker-compose.yaml` file to pass in the new tag, right? – pkaramol Apr 14 '21 at 15:27