<pre><code>  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice; do echo waiting for myservice; sleep 2; done"]
</code></pre>

<p>I am using nslookup to wait until another service comes up. However, that does not solve my problem. As service will comes up but the corresponding app - pod maybe not ready. In this case, service dependency wont be handle.</p>

<p>How to ensure that one app1 is running before start app2?</p>

<p>I had similar problems with docker-compose in the past. There are two approaches I used to resolve them. Both of them assume that services will expose a port to listen to.</p>

<ol>
<li><strong>Simple and easy</strong>: wait for the specific port of the application to be up an listening with a timeout command. This is very similar to what you are already doing. So your <code>command</code> will be something like:

<pre class="lang-yaml prettyprint-override"><code>initContainers:
- name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until timeout 2 bash -c \"&lt;/dev/tcp/myservice/${MY_SERVICE_TCP_PORT}\"; do echo waiting for myservice; sleep 2; done"]
</code></pre></li>
<li><strong>Versatile but with extra dependency</strong>: Use the wonderful <a href="https://github.com/jwilder/dockerize" rel="nofollow noreferrer">dockerize</a> tool. A lightweight binary that will control the dependencies between containers. It also does many other things, like control the log from a log file, or perform configuration templating. The only downside is that you are introducing a new dependency in your container, but in my opinion is totally worth it. In this case you can perform tcp and http checks of liveness for the services, and even introduces headers in the http ones (very useful for authenticated endpoints).</li>
</ol>
