Migrating from Docker for Mac

So you don't want to use Docker for Mac anymore, huh?

First, let's install docker and virtualbox.

brew install docker docker-machine
brew install --cask virtualbox

Now let's create a "docker machine" using docker-machine. This wraps around virtualbox to spin up a vm (and probably does other stuff).

docker-machine create --driver virtualbox \
               --virtualbox-cpu-count "4" \
               --virtualbox-memory "8192" \
               default

Now we'll set up a credential store for docker.

curl -O https://github.com/docker/docker-credential-helpers/releases/download/v0.6.4/docker-credential-osxkeychain-v0.6.4-amd64.tar.gz
tar -xvf docker-credential-osxkeychain-v0.6.4-amd64.tar.gz
sudo mv docker-credential-osxkeychain /usr/local/bin/
sudo chmod +x docker-credential-osxkeychain
sed -i 's/desktop/osxkeychain/g' ~/.docker/config.json

Let's install Kubernetes.

brew install kubectl minikube
minikube start

And then, if you use zsh / oh-my-zsh, you might like this. (Ok, yes, you can use this with bash too, just put it in the right place)

cat <<EOF >> ~/.zshrc
docker-start() {
    docker-machine start default
    eval $(docker-machine env default)
}

docker-stop() {
    docker-machine stop default
}

_docker() {
	if [ -z "${DOCKER_HOST}" ]; then
		eval $(docker-machine env)
	fi

	docker "$@"
}
alias docker=_docker
alias d=_docker
alias k=kubectl
EOF

And, finally, if you really, really, want to go all out and have docker start on your machine start (which sounds nice but your computer might not like it):

~/Library/LaunchAgent/com.docker.startup.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:</string>
        </dict>
        <key>Label</key>
        <string>com.docker.startup</string>
        <key>Program</key>
        <string>/Users/YOURUSERNAME/Library/Application Support/Docker/startup.sh</string>
        <key>RunAtLoad</key>
        <true />
        <key>KeepAlive</key>
        <false />
        <key>Disabled</key>
        <false />
        <key>LaunchOnlyOnce</key>
        <true />
        <key>StandardOutPath</key>
        <string>/tmp/docker.startup.stdout.log</string>
        <key>StandardErrorPath</key>
        <string>/tmp/docker.startup.stderr.log</string>
    </dict>
</plist>

~/Library/Appication Support/Docker/startup.sh

#!/bin/bash
docker_tag="Docker"

/usr/local/bin/docker-machine ls --filter "Name=default" --filter "State=Running" -f "{{ .Name }}"
machine_name=`/usr/local/bin/docker-machine ls --filter "Name=default" --filter "State=Running" -f "{{ .Name }}"`

if [[ ( -z "${machine_name}" || "${machine_name}" == "machine does not exist" ) ]]; then
    # Launch the machine
    echo "Starting \`default\` machine" | logger -t "${docker_tag}" -p "user.notice"

    # Redirect stderr to logger user.error
    # Redirect stdout to logger user.notice
    /usr/local/bin/docker-machine start default 2> >(logger -t "${docker_tag}" -p "user.error") 1> >(logger -t "${docker_tag}" -p "user.notice")
else
    echo "\`default\` machine is running" | logger -t "${docker_tag}" -p "user.notice" 
fi

Then,

sudo chmod +x ~/Library/Application Support/Docker/startup.sh
launchctl load -w ~/Library/LaunchAgent/com.docker.startup.plist

You can watch it via log stream | grep -i Docker.