title: How to add a docker health check to test a tcp port is open?
body: <p>I have a server which is running an apache hive service on port 9083. The thing is it doesn't support <code>http</code> protocol (but uses <code>thrift</code> protocol).so I can't simply add </p>
  
  <pre><code>HEALTHCHECK CMD http://127.0.0.1:9083 || exit 1 #  this check fails
  </code></pre>
  
  <p>All I want is to check if that port is open. I have <code>netstat</code> and <code>curl</code> on server but not <code>nc</code>.</p>
  
  <p>So far I tried the below options, but none of them is suitable as a health check.</p>
  
  <pre><code>netstat -an | grep 9083 | grep LISTEN | echo $?  # This works
  netstat -an | grep 9084 | grep LISTEN | echo $? # but so does this
  </code></pre>
  
  <p>The problem as I interpret from the above is it's simply telling me my syntax is correct, but not really testing if that port is really listening</p>
  
  <p>because when I do <code>netstat -an</code> I get the following output,which clearly shows only <code>9083</code> is listening but not <code>9084</code></p>
  
  <pre><code>Active Internet connections (servers and established) Proto Recv-Q Send-Q Local  Address           Foreign Address         State tcp       0      0 
   0.0.0.0:9083            0.0.0.0:*               LISTEN tcp    0      0 
  </code></pre>