Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A shell script that uses curl to see if docker is up and running
#!/bin/bash
rep=$(curl -s --unix-socket /var/run/docker.sock http://ping > /dev/null)
status=$?
if [ "$status" == "7" ]; then
echo 'not connected'
exit 1
fi
echo 'connected'
exit 0
@vnijs

This comment has been minimized.

Copy link

@vnijs vnijs commented Jul 9, 2018

Works great on macOS. Thanks @peterver. Do you know of something similar that would work on Windows perhaps?

@vnijs

This comment has been minimized.

Copy link

@vnijs vnijs commented Jul 9, 2018

Found something that works on macOS and on Windows if git bash is installed. On macOS open /Applications/Docker.app would start the docker deamon. Haven't seen anything similar for Windows however.

## check docker is running at all
## based on https://stackoverflow.com/questions/22009364/is-there-a-try-catch-command-in-bash
{
  docker ps -q
} || {
  echo "Docker is not running. Please start docker on your computer"
  echo "When docker has finished starting up press [ENTER} to continue"
  read
}
@wilsonmar

This comment has been minimized.

Copy link

@wilsonmar wilsonmar commented Jan 21, 2020

This is elegant thinking out of the box. Bravo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.