Last active
May 24, 2021 06:13
-
-
Save frogamic/70b32f7c332a8766ea2fcdb246cdede4 to your computer and use it in GitHub Desktop.
Wrapper to launch docker.app if it is not running when you use a CLI docker command
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
#! /usr/bin/env bash | |
set -Euo pipefail | |
DOCKER_APP="/Applications/Docker.app" | |
DOCKER_CLI="${DOCKER_APP}/Contents/Resources/bin/docker" | |
pgrep -qf Docker.app | |
if [ $? != 0 ]; then | |
read -n1 -p "The Docker app is not running, launch it now? [Y/n]" LAUNCH_DOCKER | |
[[ "$LAUNCH_DOCKER" =~ [nN] ]] && exit 0 | |
echo "" | |
echo -n "Launching " | |
open $DOCKER_APP | |
$DOCKER_CLI ps &> /dev/null | |
while [ $? != 0 ]; do | |
sleep 1 | |
echo -n "." | |
$DOCKER_CLI ps &> /dev/null | |
done | |
echo "" | |
fi | |
exec "$DOCKER_CLI" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment