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 ?

  • Is docker a solution for making application cross platform?
  • Running a Docker image in PyCharm causes “Invalid volume specification”
  • Installing sensu, sensu-dashboard does not install
  • babel-watch doesn't work from docker container on windows host when mounting a host directory as a network share
  • Dokku and log management
  • Invalid value “zookeeper” for flag -a: valid streams are STDIN, STDOUT and STDERR
  • Can a container with STATUS “Exited (-1)” be fixed?
  • Dockerfile not using cache in RUN composer install command
  • Fig kafka hostPort mapping
  • Does data needs to have a specific format to upload it in Docker?
  • Installing Java on docker in docker image
  • Jenkins build failing due to docker on GCE
  • 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.