Search code examples
macosdockerdocker-machine

How can I start a Docker container on boot in OS X?


How can I configure a Docker container to (reliably) start on boot in OS X Yosemite? I've tried various approaches using LaunchAgents, Kitematic, .bash_profile, etc. but haven't come up with a bulletproof way of ensuring that the following commands run without issue (VirtualBox crashes, race conditions, path/environment issues, etc.):

/path/to/docker-machine start default

eval "$(/path/to/docker-machine env default)"

/path/to/docker start server


Solution

  • Try breaking the two steps apart. Start Virtualbox with a LaunchAgent, then delegate starting the container to a startup script inside the docker host. This avoids both race conditions and environment issues.

    It should solve everything bar Virtualbox crashes, which is probably a whole question to itself.