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 ?

  • How to exclude some paths when mounting the volume?
  • Why is my Tutum service starting then within 2 seconds stopping with a container status “die” command?
  • Run commands on Docker container from Emacs
  • docker how to commit but exclude directory from image
  • Docker mesosphere/chronos container fails immediately after launch
  • Using a dedicated proxy container in front of Rails app container
  • Error running docker and nodemcu-build in linux (debian)
  • How to connect two HA group containers in Bluemix?
  • Flask, Gunicorn, NGINX, Docker : What is properly the way to config SERVER_NAME and proxy_pass?
  • Slow performance on Docker Containers as a Compile and Run Sandbox
  • Docker image TCP buffer size
  • Two-way authentication in Docker
  • 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.