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?

  • pass arguments from docker run to dockerfile
  • docker run with ENTRYPOINT containing a variable
  • Unable to deploy my application to remote docker
  • Docker db container running. Another process with pid <id> is using unix socket file
  • How to add initial users when starting a RabbitMQ Docker container?
  • Pandoc HTML to DOCX images load locally but not on server
  • 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

  • How to handle shell expansion in docker-compose when setting env variables
  • Docker Swarm on native hosts
  • Docker flask uwsgi 404 on a remote host
  • Running docker build with an apt proxy
  • Docker best practice on base images and host os
  • error while executing the following commands
  • 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.