code: public final void waitForLog(final int timeout, final TimeUnit unit, final String... messages)
              throws DockerException, InterruptedException {
          final long startTime = System.currentTimeMillis();
          final long timeoutTimeMillis = startTime + TimeUnit.MILLISECONDS.convert(timeout, unit);
  
          int n = 0;
          LOGGER.info("Tailing logs for \"{}\"", messages[n]);
          final LogStream logs = client.logs(containerId, follow(), stdout(), stderr());
          while (logs.hasNext()) {
              if (Thread.interrupted()) {
                  // manual check for thread being terminated
                  throw new InterruptedException();
              }
              final String message = messages[n];
              final String log = StandardCharsets.UTF_8.decode(logs.next().content()).toString();
              if (log.contains(message)) {
                  LOGGER.info(
                          "Successfully received \"{}\" after {}ms",
                          message,
                          System.currentTimeMillis() - startTime);
                  if (++n >= messages.length) {
                      return;
                  }
              }
              if (startTime > timeoutTimeMillis) {
                  throw new IllegalStateException("Timeout waiting for log \"" + message + "\"");
              }
          }
      }
docs: Wait for nth occurrence of message to appear in docker logs within the specified timeframe.
  
  @param timeout
  timeout value
  @param unit
  timeout units
  @param messages
  The sequence of messages to wait for
  @throws DockerException
  if docker throws exception while tailing logs
  @throws InterruptedException
  if thread interrupted while waiting for timeout