Testing connection to docker daemon

I am writing a script that will boot docker-compose automatically.

However, sometimes, doing eval "$(docker-machine env default)" doesn’t cause the docker daemon to be connected immediatly and when the next line comes (docker-compose up) I get Cannot connect to the Docker daemon. Is the docker daemon running on this host?

  • Build container found dead before completing the build. Build container died because it was out of memory, or the Docker image was missing glibc
  • Linking web app to mongoDB in Docker
  • Does the OCF spec mean that Docker is no longer Linux centric?
  • How can I set negative niceness of a docker process?
  • Docker installation on Ubuntu 12.04 -> cannot connect to daemon
  • Run py.test in a docker container as a service
  • If I use sleep for a few seconds the issue resolves.

    Is there a way to test the connect to daemon via some system tool (checking if a process exists, if a network connect was made, port listened to, etc)? I want to test the docker daemon externally and not use docker cli

  • Redis: ERR Rewriting config file: Permission denied when using Docker data volume
  • Dockerfile changes are not in Docker image
  • How to create docker image from jenkins running on docker
  • How can I make `avahi` work outside when `netatalk` running inside docker on `ubuntu`?
  • Docker architecture for hosting a PHP website
  • Vagrant + Docker + Tomcat: sharing webapps folder with container
  • One Solution collect form web for “Testing connection to docker daemon”

    The Docker Remote API has a PING endpoint. You can use the endpoint to check whether you can successfully connect to the Docker daemon. docker-machine env sets the environment variable DOCKER_HOST, so you can use DOCKER_HOST as host to ping. Using nc, you can ping the host as follows:

    $ eval "$(docker-machine env default)"
    $ echo -e "GET /_ping HTTP/1.1\r\n" | nc $DOCKER_HOST
    HTTP/1.1 200 OK
    Server: Docker/1.10.2 (linux)
    Date: Thu, 03 Mar 2016 07:05:58 GMT
    Content-Length: 2
    Content-Type: text/plain; charset=utf-8
    
    OK
    

    You will need to check the return value. If it returns ‘OK’, the connection was successful. A simple check could look as follows (this probably needs more refinement):

    #!/bin/bash
    if [ "$(echo -e "GET /_ping HTTP/1.1\r\n" | nc $DOCKER_HOST | tail -n 1)" == 'OK' ] ; then
      echo "You are connected"
    fi
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.