Created
July 12, 2020 14:24
-
-
Save michaeldlfx/2e01e108ec2a67764a565fa44c47f873 to your computer and use it in GitHub Desktop.
[MacOS] Start docker if daemon is not 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
# This snippet works well as part of a .bash_profile file. | |
# It's based on this StackOverflow post: https://stackoverflow.com/a/48843074/11488212 | |
# This docker daemon is a resource hog, and doesn't always need to be running imho. | |
# I predent the below declared alias "dr" to all my docker aliases to start up the docker daemon if it's not already running. | |
# This way, I don't get the annoying 'ERROR: Couldn't connect to Docker daemon. You might need to start Docker' message anymore. | |
# Example usage: "alias dcu="dr ; docker-compose up" | |
alias dr="dockerReady" | |
alias isDockerRunning="(docker stats --no-stream) > /dev/null 2>&1" | |
dockerReady() { | |
if (isDockerRunning); then | |
return | |
elif (! isDockerRunning); then | |
open /Applications/Docker.app | |
echo -n "Waiting for docker to be ready" | |
while (! isDockerRunning); do | |
echo -n "." | |
sleep 1 | |
done | |
echo "done." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment