These are my notes for setting up Docker on macOS. I like this method because it lets us use Docker without signing in, and lets us manage the Docker Daemon with the command line.
Use Homebrew
Use Homebrew.
Install Docker.app.
brew cask install docker
Install the Docker Toolbox.
brew install docker
Manage the Docker Daemon
I prefer to manage the Docker daemon with the CLI. I use the method outlined in this Stack Overflow post. These scripts are taken from that post, and are posted here for convenience and archival. I like to have these available in any directory, so I’ll add them to my path.
Make a bin dir for your user, if you don’t already have one.
mkdir ~/bin
Add to your path with pathman, or using the method you prefer.
pathman add $HOME/bin
Create an empty file for docker-start
.
touch bin/docker-start
Copy and paste the docker-start
script.
#!/usr/bin/env bash
case $1 in
-h|--help)
echo $'usage: docker-start\n\nStarts Docker (Docker.app) on macOS and waits until the Docker environment is initialized.'
exit 0
;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }
[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }
echo "-- Starting Docker.app, if necessary..."
open -g -a Docker.app || exit
# Wait for the server to start up, if applicable.
i=0
while ! docker system info &>/dev/null; do
(( i++ == 0 )) && printf %s '-- Waiting for Docker to finish starting up...' || printf '.'
sleep 1
done
(( i )) && printf '\n'
echo "-- Docker is ready."
Create an empty file for docker-stop
.
touch bin/docker-stop
Copy and paste the docker-stop
script.
#!/usr/bin/env bash
case $1 in
-h|--help)
echo $'usage: docker-stop\n\nStops Docker (Docker.app) on macOS.'
exit 0
;;
esac
(( $# )) && { echo "ARGUMENT ERROR: Unexpected argument(s) specified. Use -h for help." >&2; exit 2; }
[[ $(uname) == 'Darwin' ]] || { echo "This function only runs on macOS." >&2; exit 2; }
echo "-- Quitting Docker.app, if running..."
osascript - <<'EOF' || exit
tell application "Docker"
if it is running then quit it
end tell
EOF
echo "-- Docker is stopped."
echo "Caveat: Restarting it too quickly can cause errors."
Get to Work
Now you have the Docker.app, command line capabilities, auto completion, and handy scripts to start and stop Docker Daemon.