-1

I have 3 services defined in docker-compose A, B and C. B and C depends_on A. If A's healthcheck results in unhealthy, I want other 2 containers not be spinned up. Currently, containers B and C are started only when container A is started with healthy status, and this is my expected behaviour. However, if container A becomes unhealthy after it gets created, I don't want dependent containers to be started, currently when A is created and becomes unhealthy only one of the other 2 container exits (sometimes A exits and other times B but not both). Here's the output when A is unhealthy.

Creating A ... done 
Creating C ... done  
ERROR: for B  Container "1339a6d12091" is unhealthy. ERROR: Encountered errors while bringing up the project. 

As we can see here in the ERROR message, only for B it shows 1339a6d12091(container A) is unhealthy. Whereas it should have reported this error for both B and C containers.

docker-compose

version: '2.3'
    
    services:
      B:
        image: base_image
        depends_on:
           A:
             condition: service_healthy
        entrypoint:  bash -c "/app/entrypoint_scripts/execute_B.sh"
      C:
        image: base_image
        depends_on:
          A:
            condition: service_healthy
        entrypoint: bash -c "/app/entrypoint_scripts/execute_C.sh"
      A:
        image: base_image
        healthcheck:
          test: ["CMD-SHELL", "test -f /tmp/compliance/executedfetcher"]
          interval: 30s
          timeout: 3600s
          retries: 1
        entrypoint: bash -c "/app/entrypoint_scripts/execute_A.sh"

My Expectation: B and C should wait for A to become healthy before starting (which is working fine for me). If A starts and become unhealthy without becoming healthy even for once B and C should not start.

Saurabh
  • 63
  • 6
  • 1
    Does this answer your question? [What is the alternative to condition form of depends\_on in docker-compose Version 3?](https://stackoverflow.com/questions/47710767/what-is-the-alternative-to-condition-form-of-depends-on-in-docker-compose-versio) – crizzis Apr 26 '21 at 05:43
  • https://docs.docker.com/compose/startup-order/ – J Asgarov Apr 26 '21 at 05:44
  • @crizzis Nope, that doesn't seems to be helpful. – Saurabh Apr 26 '21 at 07:05
  • The answer tells you that `condition` is no longer supported – crizzis Apr 26 '21 at 07:11

1 Answers1

0

Container A was exiting immediately after becoming unhealthy, as a result, the status: unhealthy was not available for long enough for other containers to read its value. The status: unhealthy was visible only for a fraction of a second and in that fraction of a second only one of the container (either A or B) was able to read it.

I added a sleep 100 statement in the execute_A.sh entrypoint script after the container was becoming unhealthy so that both B and C can easily read A's status, and that fixed the issue.

Saurabh
  • 63
  • 6