title: docker python api: how do I know when instance is ready?
body: <p>I have a python module that starts a brand new docker postgres container like so:</p>
  
  <pre><code>import docker, time
  
  client = docker.from_env()
  
  containers = client.containers.list(all=True) # all checks for dead ones
  
  container = client.containers.run(
      image="postgres",
      detach=True,
      ports={5432: 5555},
      name="postgres_test",
      user="postgres",
      environment={"POSTGRES_PASSWORD": "foo", "POSTGRES_DB": "test_db"}
  )
  time.sleep(10)
  </code></pre>
  
  <p>The code above works. One thing that I'm not particularly fond of is the last statement - <code>time.sleep(10)</code>. Instead of sleeping, I would rather the <code>docker.containers.run()</code> blocks or I query the container to find out when it has initialised.</p>
  
  <p>How can I remove the <code>time.sleep(10)</code> line and have blocking functionality ?</p>