Sequential Docker compose execution

We have a docker compose file in which we want to run jobs one after another.

PS: depends_on don’t work here because that waits for service to start and we want to run service just after one service gets finish.

If you use the long depends_on syntax, you can use the condition service_completed_successfully to make a service wait for another service’s container to complete successfully (as in not terminated with an exit code other that 0).

services:
  job1:
    image: job1:tag
    restart_policy: never
  job2:
    image: job2:tag
    depends_on:
      job1:
        condition: service_completed_successfully
        restart: false
   restart_policy: never

see: https://docs.docker.com/compose/compose-file/05-services/#long-syntax-1

Thank you for your comment. It really works.