Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 89 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save andystanton/257fab335b242bc2658b to your computer and use it in GitHub Desktop.
Save andystanton/257fab335b242bc2658b to your computer and use it in GitHub Desktop.
Start up local Docker Machine on OSX automatically.
<?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>{{user-path}}</string>
</dict>
<key>Label</key>
<string>com.docker.machine.default</string>
<key>ProgramArguments</key>
<array>
<string>{{docker-machine}}</string>
<string>start</string>
<string>default</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Notice

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.

Requirements

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

Usage

$ curl -sL https://gist.githubusercontent.com/andystanton/257fab335b242bc2658b/raw/c62ae413a0a45ec5d832fb04065a085a8fb477da/com.docker.machine.default.plist | \
    sed -e "s?{{docker-machine}}?$(which docker-machine)?" \
        -e "s?{{user-path}}?$PATH?" \
    >~/Library/LaunchAgents/com.docker.machine.default.plist && \
    launchctl load ~/Library/LaunchAgents/com.docker.machine.default.plist
@im-kulikov
Copy link

@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@192.168.64.14 -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
Copy link

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 com.docker.machine.dev.plist into /Library/LaunchDaemons/, add

<key>UserName</key>
<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/com.docker.machine.dev.plist

then everything is fine.

@msabramo
Copy link

This worked great for me. Thanks, @andystanton!

@rantoniuk
Copy link

Good job, thanks @andystanton!

@jbarlow83
Copy link

For homebrew users:
brew services start docker-machine

@andysign
Copy link

In my case the entire process of starting up the docker-machine was slow... because of that I was forced to add the following:
while [ "$(docker-machine ls --filter name=default -f '{{.Error}}')" != "" ] && [ "$(docker-machine ls --filter name=default -f '{{.URL}}')" == "" ]; do sleep 1; done; eval $(docker-machine env default);
in
.bash_profile

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