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

已提問 2 年前檢視次數 1960 次
1 個回答
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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南