Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Start up local Docker Machine on OSX automatically.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">


This script is no longer required with Docker for Mac which includes an option to run Docker at startup and doesn't use docker-machine to administer the local Docker engine.


  • Docker Machine + Docker
  • curl
  • A Virtualbox-driven Docker Machine called "default" docker-machine create --driver virtualbox default (this is the default with Docker toolkit).


The URL ( is a shortened form of the raw url of the plist.

$ curl -sL | \
    sed -e "s?{{docker-machine}}?$(which docker-machine)?" \
        -e "s?{{user-path}}?$(echo $PATH)?" \
    >~/Library/LaunchAgents/com.docker.machine.default.plist && \
    launchctl load ~/Library/LaunchAgents/com.docker.machine.default.plist

certik commented Apr 6, 2016

@andystanton, I just tried it and it works! Thanks for preparing this.

I also put the following into my ~/.bashrc:

eval $(docker-machine env default)

So now I can use the docker command from my terminal just like if I was on Linux.


andystanton commented Apr 8, 2016

I'm glad it was useful @certik!

@certik this worked for me! Thanks again @andystanton

TrevorSayre commented May 18, 2016

Why not place the following in your startup file
e.g. ~/.bashrc, ~/.zshrc, etc.

if docker-machine status $DOCKER_MACHINE | grep "Running" &> /dev/null
    eval "$(docker-machine env $DOCKER_MACHINE)"
    docker-machine start $DOCKER_MACHINE && eval "$(docker-machine env $DOCKER_MACHINE)"

For fish place the following in ~/.config/fish/

if docker-machine status $DOCKER_MACHINE | grep "Running" > /dev/null
  eval (docker-machine env $DOCKER_MACHINE)
  docker-machine start $DOCKER_MACHINE and eval (docker-machine env $DOCKER_MACHINE)

andystanton commented May 18, 2016

@TrevorSayre that starts Docker only when you begin a terminal session after logging in. Using the launchctl script starts Docker when you log in, and is agnostic to what shell you use.

@andystanton Thank you for the response. I guess that difference doesn't affect me, I only use Docker in my terminal.

ellisio commented Jun 30, 2016

For some reason this does not start my Docker Machine on boot. OS-X 10.11.5 running the latest Docker Toolbox.


andystanton commented Jul 1, 2016

Hi @ellisio, can you let me know the output of the following commands:

echo $PATH
cat ~/Library/LaunchAgents/com.docker.machine.default.plist
launchctl list | grep docker
which docker-machine
docker-machine --version
docker-machine ls
which docker
docker --version


echo $PATH


cat ~/Library/LaunchAgents/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

launchctl list | grep docker

$ launchctl list | grep docker
2805    0   com.docker.machine.default

which docker-machine:


docker-machine --version:

docker-machine version 0.8.2, build e18a919

docker-machine ls:

$ docker-machine ls
dev             xhyve    Timeout

which docker:

$ which docker

docker --version:

$ docker --version
Docker version 1.12.1, build 23cf638

StandardErrorPath + StandardOutPath:

==> /usr/local/var/log/dockermachine-errors.log <==

==> /usr/local/var/log/dockermachine-status.log <==
Starting "dev"...
(dev) Waiting for VM to come online...
(dev) Waiting on a pseudo-terminal to be ready... done
(dev) Hook up your terminal emulator to /dev/ttys003 in order to connect to your VM

==> /usr/local/var/log/dockermachine-errors.log <==
Too many retries waiting for SSH to be available.  Last error: Maximum number of retries (60) exceeded

@andystanton if I add --debug to run command, like this docker-machine --debug start dev, then i see next (looping this message):

(dev) DBG | SSH cmd err, output: exit status 255:
(dev) DBG | Error getting ssh command 'exit 0' : Something went wrong running an SSH command!
(dev) DBG | command : exit 0
(dev) DBG | err     : exit status 255
(dev) DBG | output  :
(dev) DBG |
(dev) DBG | Getting to WaitForSSH function...
(dev) DBG | Using SSH client type: external
(dev) DBG | {[-o BatchMode=yes -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none docker@ -o IdentitiesOnly=yes -i /Users/kulikov-im/.docker/machine/machines/dev/id_rsa -p 22] /usr/bin/ssh}
(dev) DBG | About to run SSH command:
(dev) DBG | exit 0

suplo commented Nov 2, 2016

In my case, I want to start the docker-machine when booting (not when user logging in), so I put into /Library/LaunchDaemons/, add

<string>{{ your_username }}</string>

as running docker-machine as root will throw Host does not exist: "default"

beside that, change file's owner to root:wheel

sudo chown root:wheel /Library/LaunchDaemons/

then everything is fine.

This worked great for me. Thanks, @andystanton!

warden commented Jun 6, 2017

Good job, thanks @andystanton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment