One-shot docker containers using Docker compose

0

I have a distributed application set up in a Docker environment. Currently, I am able to run the application in my local machine, using docker-compose to start both the manager and the workers. The docker-compose.yaml file looks similar to this:

version: "3"
services:
  manager:
    image: ${IMAGE}
    command: binary start-manager --port 1234
  worker:
    image: ${IMAGE}
    command: binary start-worker --address manager --port 1234
    depends_on:
      - manager
    deploy:
      replicas: 2

This application is meant to run once, and when the manager finishes, it stops the workers and then stops itself. Currently, I am able to run the application in AWS using a docker context (I followed this).

The main problem I have is that once it is run using docker --context myContext compose up, it creates ECS services that, once the specific task finishes, it creates a new task; so I have to monitor the containers and run docker --context myContext compose down when it finishes.

I found that service.deploy.restart_policy is not implemented, so my question is: can I run this application once, and ensure that no tasks are spawned again once the manager service stops?

Thanks,

Josep

gefragt vor 2 Jahren1959 Aufrufe
1 Antwort
0

As you mentioned, the Docker tooling will create ECS Services which are designed to keep your containers always running (like a web server, for example). In order to achieve your outcome (run the manager/workers to completion then stop), you'll want to register a Task Definition that includes both containers, then use the ECS RunTask API to run a single instance of your Task Definition.

profile pictureAWS
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen