<p>Lets say I have 3 containers X,Y and Z. I want container Y to start only after container X is running, and container Z to start only after Y is running.</p>

<p>How do I do this?</p>

<p>You can use <a href="https://docs.docker.com/compose/overview" rel="nofollow noreferrer"><code>docker-compose</code></a> file with the <a href="https://docs.docker.com/compose/compose-file/#dependson" rel="nofollow noreferrer"><code>depends_on</code></a> option to control container start order</p>

<p>Here is how the <code>docker-compose.yml</code> for your example would look like:</p>

<pre><code>version: '3'
services:
  X:
    image: X_image

  Y:
    image: Y_image
    depends_on: X

  Z:
    image: Z_image
    depends_on: Y
</code></pre>

<blockquote>
  <p><strong>Note</strong>: <code>depends_on</code> will not wait for X to be “ready” before starting Y - only until it's running. If you need to wait for a service to be ready, see <a href="https://docs.docker.com/compose/startup-order" rel="nofollow noreferrer">Controlling startup order</a> for more on this problem and strategies for solving it.</p>
</blockquote>
