Inspired by this article from Alex I also set out to remove always running Docker daemon from the background while ensuring it is available whenever I need it on running docker
or docker-compose
commands.
I created 2 scripts and put them on my path before the actual docker
and docker-compose
binaries. For an explanation of the scripts I suggest you read Alex's article linked above.
#!/usr/bin/env bash
set -o errexit
set -o nounset
is_docker_running() {
if /usr/local/bin/docker info > /dev/null 2>&1; then
return 0
else
return 1
fi
}
if ! is_docker_running; then
echo "Starting Docker..."
open /Applications/Docker.app
for i in $(seq 60)
do
if is_docker_running; then
break
fi
sleep 1
done
fi
/usr/local/bin/docker "$@"
I named the above file docker
, gave it executable permissions and did a similar thing for docker-compose
#!/usr/bin/env bash
set -o errexit
set -o nounset
is_docker_running() {
if /usr/local/bin/docker info > /dev/null 2>&1; then
return 0
else
return 1
fi
}
if ! is_docker_running; then
echo "Starting Docker..."
open /Applications/Docker.app
for i in $(seq 60)
do
if is_docker_running; then
break
fi
sleep 1
done
fi
/usr/local/bin/docker-compose "$@"
Thanks again to Alex for the inspiration.