title: Docker compose wait for without sleep command
body: <p>I've read lots for similar topics; 
  For example this: 
  <a href="https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y">Docker Compose wait for container X before starting Y</a> etc.</p>
  
  <p>So, I'm trying to implement a wait for only using compose and health checks.</p>
  
  <p>I have only one docker-compose file. There is a section for the app and for test for this app. </p>
  
  <p>Test (service) can be executed only when app(jar, db etc) will be ready. 
  Also after test (service) execution, I want to get status for this execution via $?</p>
  
  <p>So my compose file is next: </p>
  
  <pre><code>version: "2.1"
  networks:
    myNetwork:
  services:
    rabbitmq:
     ... 
      networks:
        - myNetwork
      healthcheck:
        test: ["CMD", "rabbitmqctl", "status"]
        interval: 100s
        timeout: 10s
        retries: 10
    app:
      ...
      depends_on:
        rabbitmq:
          condition: service_healthy
      networks:
        - myNetwork
      healthcheck:
        test: ["CMD", "wget", "http://localhost:8080/ping"]
        interval: 100s
        timeout: 10s
        retries: 10
  
    tests:
      build:
        context: .
        dockerfile: TestDocker
      depends_on:
        app:
          condition: service_healthy
      networks:
        - myNetwork
  </code></pre>
  
  <p>Im trying to run:</p>
  
  <pre><code>docker-compose up -d app &amp;&amp; docker-compose run tests;
  </code></pre>
  
  <p>or </p>
  
  <pre><code>docker-compose run tests
  </code></pre>
  
  <p>But  <code>docker-compose run tests</code> don't waits for  condition: service_healthy; (app and rabbitmq containers is started but service_healthy was not checked);</p>
  
  <p><strong>And this is the problem.</strong></p>
  
  <p>When I do something like this: </p>
  
  <pre><code>  docker-compose up -d app &amp;&amp; sleep 20 &amp;&amp; docker-compose run tests;
  </code></pre>
  
  <p>So is there is any possibility to do sleep or wait for, for command: docker-<code>compose run tests</code> ?</p>