title: How to detect if docker container crashed
body: <p>I am running a process every 5 minutes and checking to make sure every container. If the container does not respond I can flag it as down. I have the containers IP address and I loop through each ip and check if it responds to a ping. If not I flag it as down. Is there a better way to do this? My code:</p>
  
  <pre><code>@Transactional
  @Scheduled(fixedRate = 1000 * 60)   //5 min
  public void monitorHosts(){
      Iterable&lt;Ncl&gt; ncls = nclRepository.findAll();
  
      for(Ncl ncl: ncls){
          for(String host: ncl.getHosts()){
              Boolean isHostAlive = isHostAlive(host);
              if(!isHostAlive){
                  Ncl nclWorking = nclRepository.findOne(ncl.getUuid());
                  if(nclWorking != null){
                      Set&lt;String&gt; hosts = nclWorking.getHosts().stream().filter(x -&gt; x.equals(host)).collect(Collectors.toSet());
                      nclWorking.getHosts().clear();
                      nclWorking = nclRepository.save(nclWorking);
                      nclWorking.setHosts(hosts);
                      nclRepository.save(nclWorking);
                  }
              }
          }
      }
  }
  
  private Boolean isHostAlive(String host){
      try{
          InetAddress address = InetAddress.getByName(host);
          boolean reachable = address.isReachable(10000);
          return reachable;
      } catch (Exception e){
          e.printStackTrace();
          return false;
      }
  }
  </code></pre>