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년 전1959회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠