How to know if my program is completely started inside my docker with compose

In my CI chain I execute end-to-end tests after a “docker-compose up”. Unfortunately my tests often fail because even if the containers are properly started, the programs contained in my containers are not.

Is there an elegant way to verify that my setup is completely started before running my tests ?

  • What is the difference between “docker logs” and “docker attach”?
  • Confluent Platform : Update Schema Registry to use Avro 1.8.1 and use new build in docker and host
  • Docker container network failed Occasionally
  • How to run docker image with specific version and port forwarding
  • How to bundle install a local path gem with docker?
  • Multiple dokku apps one domain
  • Is it possible running docker on big endian, arm32, linux=2.6.34?
  • Passing ES_JAVA_OPTS variable with spaces when using docker compose
  • redirect log files created in a docker container to stdout / stderr
  • Managing docker-compose override files
  • How to configure GWT debugging with docker?
  • block device access on windows docker tool box
  • 2 Solutions collect form web for “How to know if my program is completely started inside my docker with compose”

    You could poll the required services to confirm they are responding before running the tests.

    curl has inbuilt retry logic or it’s fairly trivial to build retry logic around some other type of service test.

    #!/bin/bash
    
    await(){
      local url=${1}
      local seconds=${2:-30}
      curl --max-time 5 --retry 60 --retry-delay 1 \
           --retry-max-time ${seconds} "${url}" \
      || exit 1
    }
    
    docker-compose up -d
    await http://container_ms1:3000
    await http://container_ms2:3000
    run-ze-tests
    

    The alternate to polling is an event based system.
    If all your services push notifications to an external service, scaeda gave the example of a log file or you could use something like Amazon SNS. Your services emit a “started” event. Then you can subscribe to those events and run whatever you need once everything has started.

    Docker 1.12 did add the HEALTHCHECK build command. Maybe this is available via Docker Events?

    If you have control over the docker engine in your CI setup you could execute docker logs [Container_Name] and read out the last line which could be emitted by your application.

    RESULT=$(docker logs [Container_Name] 2>&1 | grep [Search_String])

    logs output example:
    Agent pid 13
    Enter passphrase (empty for no passphrase): Enter same passphrase again: Identity added: id_rsa (id_rsa)
    #host SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
    #host SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6

    parse specific line:
    RESULT=$(docker logs ssh_jenkins_test 2>&1 | grep Enter)

    result:
    Enter passphrase (empty for no passphrase): Enter same passphrase again: Identity added: id_rsa (id_rsa)

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.