Created
November 11, 2017 16:58
-
-
Save peterver/ca2d60abc015d334e1054302265b27d9 to your computer and use it in GitHub Desktop.
A shell script that uses curl to see if docker is up and running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
}
This is elegant thinking out of the box. Bravo!
This is elegant thinking out of the box. Bravo!
Thanks, @vnijs here are the errors that docker ps -q
will throw if docker is not running or booting up.
Error response from daemon: dial unix docker.raw.sock: connect: connection refused
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
OMG, I also found your answer on this stack overflow!!! 💥 https://stackoverflow.com/a/51251499/882371
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works great on macOS. Thanks @peterver. Do you know of something similar that would work on Windows perhaps?