0

I've in Dockerfile service which depends on another service, but I'd like to negate the condition when not service_healthy. So opposite of the following:

service1:
    depends_on:
      service2:
        condition: service_healthy

So basically I'd like to start service1 when service2 is not healthy.

Secondly, based on the documentation for depends_on, the condition option has been removed and it is no longer supported in version 3 of Compose file format.

So how the above logic can be achieved?

kenorb
  • 155,785
  • 88
  • 678
  • 743

1 Answers1

0

Here is the workaround where main container waits for other hosts to exit, by pinging the other hosts and waiting when both are off-line:

version: '3'
services:
  main:
    image: bash
    depends_on:
     - test01
     - test02
    command: bash -c "sleep 2 && until ! ping -qc1 test01 && ! ping -qc1 test02; do sleep 1; done &>/dev/null"
    networks:
      intra:
        ipv4_address: 172.10.0.254
  test01:
    image: bash
    hostname: test01
    command: bash -c "ip route && sleep 10"
    networks:
      intra:
        ipv4_address: 172.10.0.11
  test02:
    image: bash
    hostname: test02
    command: bash -c "ip route && sleep 20"
    networks:
      intra:
        ipv4_address: 172.10.0.12
networks:
  intra:
    driver: bridge
    ipam:
      config:
      - subnet: 172.10.0.0/24

See also: Docker compose - Start service only when other service had completed

kenorb
  • 155,785
  • 88
  • 678
  • 743