
Simplifying Docker on OS X - joeyespo
https://blog.andyet.com/2016/01/25/easy-docker-on-osx/
======
shlant
From someone who has wasted many hours trying to get B2D working, I have ended
up using
[https://github.com/codekitchen/dinghy](https://github.com/codekitchen/dinghy)

Easier to use, more reliable and some nice features like the OPs .docker DNS
and NFS shares. The maintainer is very responsive and I recommend it to anyone
who is struggling with docker on OSX.

~~~
STRML
After seeing this article, I just migrated from Dinghy to Dlite. I saved about
5GB of disk space, got much faster VM startup time and basically no hassle. It
was a cinch to work my docker-compose startup into a LaunchAgent and now I
finally have all my services running on boot. I highly recommend giving it a
shot; my eyes nearly popped when I saw how quickly it downloaded and started
the VM (must have been all of a 10MB download).

~~~
Pym
As a Dinghy user too, thank you! I will give a shot at Dlite right now :)

------
kevan
I feel like this isn't much simpler than the official docker-machine workflow,
but I may be too far in the weeds at this point to objectively tell how
complicated it is. In my case I need to test tools across 4 versions of Docker
so I'm locked into using docker-machine and dvm.

~~~
jjn2009
The lack of /var/run/docker.sock is annoying but its really not that big of a
deal in my opinion either. docker-machine covers a lot of other use cases such
as multi-host docker swarms and docker in the cloud. Adding this tool to the
toolbox is extra mental overhead for a small benefit if you have any need for
these more advanced use cases.

~~~
adamsea
I also am not sure what major advantages this brings. And the article was
slightly unclear in that you can add Docker environment variables to your
`.bash_profile` -- you still are dealing with environment vars, but don't have
to run the `eval` command all the time. And, I believe the docker-machine
default VM settings mount your User (Users/myname) directory in it's virtual
machine

~~~
jjn2009
yes you are correct, docker-machine mounts your current user's folder into the
VM as well so thats not an advantage over docker-machine either.

~~~
manojlds
But that mount is vboxfs and is slow. You need to do some extra work to get
NFS going.

------
omni
There's a lot of neat work going on in this space because Docker support on OS
X is pretty lackluster out of the box. My team and I built Dusty[1] to try to
solve many of the same problems, though we seem to be operating at a bit of a
higher level than this tool.

I'm excited to try out xhyve for virtualization, but even if you solve the
virtualization problem there are still some real usability concerns around
using Docker for development in even medium-sized teams. I gave a talk at
PyGotham[2] about some of the benefits and issues of using Docker for dev at
this point.

All told, this looks like it might be an attractive lightweight solution
though if virtualization is your main problem now.

[1] [http://dusty.gc.com/](http://dusty.gc.com/) [2]
[https://www.youtube.com/watch?v=pYLOuuR7HI0](https://www.youtube.com/watch?v=pYLOuuR7HI0)

------
therealmarv
I also really hatte the official Docker way in OS X. It's even hard to
uninstall! If anybody is interested how to uninstall official Docker for OSX:
[https://therealmarv.com/how-to-fully-uninstall-the-
offical-d...](https://therealmarv.com/how-to-fully-uninstall-the-offical-
docker-os-x-installation/) Running Docker in a Vagrant VM is or was the best
way. Speaking of Vagrant... does anybody know if there is a xyhve Vagrant
project?

------
pchm
Nice work joeyespo, it's definitely a much-needed step forward. NFS, though,
is a huge pain point for me on OSX performance-wise. The only reliable
solution I've found so far is Unison sync between Mac & Vagrant (Ubuntu). That
also comes with some caveats, as Unison has to be compiled with exactly the
same version & dependencies on both OSX and Ubuntu.

If anyone's interested, I've created a list of steps involved in making it
work on El Capitan:
[https://gist.github.com/pch/aa1c9c4ec8522a11193b](https://gist.github.com/pch/aa1c9c4ec8522a11193b)

~~~
jeromenerf
FS sync, may it be for the code, the assets, the data, the logs, is painfully
slow on osx, because of vboxsf poor performance.

If you intend to use docker containers on osx as an isolated runtime, with all
your "data" sync'd in realtime between your host and your container, then use
linux.

Fswatch / Rsync / unison over NFS, ssh or cifs are hacks of a greater order
than having to source an env script.

Out of curiosity, why would you need directional sync/unison?

------
corybrown
Pretty cool trick to make the OS X docker hacks feel transparent. I've been
tempted into getting a Linux laptop just because using Docker on OS X feels so
hacky.

~~~
mr337
I did and never looked back. Lenovo X1 Carbon Gen 3

~~~
Diederich
Been using Linux on my work macbooks since 2009. There are some bumps
involved, but it works really well on the awesome Apple hardware.

~~~
corybrown
How's the battery life?

~~~
rocky1138
I use a Macbook Pro (2014) with Kubuntu Linux installed full-time. The battery
life is about half of what it is when running OSX.

If you forget your charger, there is serious range anxiety. Luckily, I've been
running PC laptops for years and have gotten completely used to bringing my
charger any time I take my laptop.

------
heurist
`eval $(docker-machine env docker)` is great, I can stick it in scripts and
separate my development environment from testing, staging, and production for
every project I need to track. It works on Windows, OS X, and Linux so all my
developers can use whatever OS they want and I still have one platform-
agnostic environment setup script that gets people up and running in less than
15 minutes. The only problem with docker-machine is you can't share
environments without copying over the entire machine configuration, which is
somewhat baffling in the case of EC2 machines but is by no means a deal-
breaker.

------
BinaryIdiot
Thank you! I'll have to check this out. It baffles me that a company such as
Docker has yet to make using its primary product on Mac OS X simple plug and
play. Needing to remember to run `eval $(docker-machine env docker)` is not a
sustainable solution. Hell I know about this and would occasionally forget and
become confused at the error messages.

In fact I put this horrible hack into my ~/.bash_profile (I wouldn't recommend
doing this but, hey, it works.):

docker-machine start dev

eval "$(docker-machine env dev)"

~~~
rocky1138
From my understanding, the limitation is from OSX and not from Docker, as OSX
does not have native support for kernel namespacing. This is why Docker on OSX
runs inside of a Linux virtual machine.

~~~
lotyrin
Making OSX Linux is hard, but making Docker smarter about running on OSX is
easy (have docker-machine provide a socket like this project does, have docker
client detect the environment and connect to the correct virtual machine's
docker socket) and would be an obvious huge step forward.

~~~
rocky1138
Yeah, sure, I agree, there's a lot of room for improvement. But, I still talk
to a lot of developers who are new to Docker and use OSX, who are confused as
to why they need to run a VM or enter docker commands into a different
terminal than they are used to.

------
sciurus
The interesting links are

[https://github.com/nlf/dhyve](https://github.com/nlf/dhyve)

[https://github.com/nlf/dhyve-os](https://github.com/nlf/dhyve-os)

------
Laaw
docker-machine is almost completely seamless to me. The _only_ thing I have to
do is start the VM, the eval is in my .profile.

This whole problem took me <5 mins to solve, and about 30s to solve each boot.
I could quite easily start the VM on boot as well, but it's such a non problem
for me that I don't even bother spending the 3 mins it'd take to set up.

------
outcoldman
Honestly, for me it looks like a wasting time. If you want to have simplicity
- install Docker Toolbox, which will help you with getting access to docker
with all environment variables. If do not need simplicity - you probably want
to handle multiple docker hosts, including VM, Linux machines, Cloud instances
- this is why you want to have an option to switch between docker environments
using `eval $(...)`. Also you can use something like
[https://github.com/Tarrasch/zsh-autoenv](https://github.com/Tarrasch/zsh-
autoenv) to automatically call this command in specific folders.

And if you really need docker-lite- you do not need to write it in go, just do

Run that once (do sudo or any other crazy stuff):

``` echo $(docker-machine ip dev) local.docker >> /etc/hosts ```

Add that to `.bashrc`

``` eval $(docker-machine eval dev) ```

------
evacchi
Unfortunately it seems that Xhyve cannot connect to the Internet when traffic
is routed through OpenVPN. Otherwise I would use it at my job. I tried
[https://github.com/coreos/coreos-xhyve](https://github.com/coreos/coreos-
xhyve), [https://github.com/ailispaw/docker-root-
xhyve](https://github.com/ailispaw/docker-root-xhyve) and Veertu, and they all
won't work.

Apparently is a known issue
[https://github.com/mist64/xhyve/issues/84](https://github.com/mist64/xhyve/issues/84)
; it might have to do with Hypervisor.framework

~~~
colordrops
Same goes for Cisco AnyConnect VPN. Updating the routing table seems to
temporarily fix it, but it would be nice not to hack around it to get it to
work.

~~~
evacchi
> Updating the routing table seems to temporarily fix it,

can you share a link ? thanks

~~~
colordrops
It's been a while, but I believe the fix is in this thread:

[https://github.com/boot2docker/boot2docker/issues/628](https://github.com/boot2docker/boot2docker/issues/628)

------
nzoschke
This looks great and is now high on my todo list to test.

I am all in on docker development because I am all in on using images and
containers in production via ECS. Getting a laptop and AWS talking the same
abstraction is the future.

I too suffer from problems with Docker Machine and virtual box on OS X.
Frequently I find myself debugging these subsystems. It's been ok because the
worst case to get back to a good state is uninstall, reboot and reinstall.
Annoying but passable b

I have also experimented with xhyve and it looks extremely promising but does
need some new tools to make it a turnkey docker dev environment.

From my survey of this technique and the tools we need more time, energy and
cooperation to get there.

Thank you and everyone else for your efforts!

~~~
toomuchtodo
> Getting a laptop and AWS talking the same abstraction is the future.

You can already do this with Vagrant and VirtualBox. Docker is just additional
abstraction.

------
beat
I used to struggle with this. Then I set up a Vagrantfile and put my docker
code in a Vagrant instance. It's just far and away better than any other hack
I've tried. File mount point transparency problems? Solved!

------
tniswong
I just use bash aliases in my .profile

\----

alias dm="docker-machine"

alias dc="docker-compose"

alias denv='function __denv() { eval "$(dm env $@)"; unset -f __denv; };
__denv'

\----

dm create --driver virtualbox local

denv local

Also works with swarm params:

denv local --swarm swarm-master

~~~
jzelinskie
The whole Quay team at CoreOS uses OSX to develop a container registry. As a
result I have a bunch of useful aliases as well[0]. A lot of them have to do
with just plain cleaning up after yourself, but I also wrap my calls to
`docker` with a zsh function that will eval my dev docker-machine environment
if it hasn't been already.

[0]:
[https://github.com/jzelinskie/dotfiles/blob/b2d33f8c601d1b7d...](https://github.com/jzelinskie/dotfiles/blob/b2d33f8c601d1b7d9cce1df3319561e182251a26/zshrc#L12-L30)

------
CommanderNyx
Hey, this is pretty sweet.

This is a simple alternative than the solution I wrote about here:
[https://allysonjulian.com/setting-up-docker-with-
xhyve/](https://allysonjulian.com/setting-up-docker-with-xhyve/) which uses
docker-machine-driver-xhyve ([https://github.com/zchee/docker-machine-driver-
xhyve](https://github.com/zchee/docker-machine-driver-xhyve)).

I've been trying to figure out how to deal with the env variables used by
docker, and used a workaround ~/.profile
([https://gist.github.com/astrohckr/efceb07887225cbc2ba2](https://gist.github.com/astrohckr/efceb07887225cbc2ba2)).
Like the OP, running eval in every terminal session makes me a bit concerned
as well.

I'll give dlite a Go.

------
Diamons
I created a very similar post not too long ago:

[http://shahruk.com/code/snippets/2016/01/18/Definitive-
Guide...](http://shahruk.com/code/snippets/2016/01/18/Definitive-Guide-To-
Making-Docker-Wordpress-Work-Mac-OSX.html)

------
arsalanb
Docker is one of the tools that was concocted (by brilliant people!) after I
began programming professionally. From my understanding, Docker allows you to
containerize your applications so they function properly anywhere you (so to
say) "place those containers".

Now, does if I'm working with say Django or Flask, and things behave
differently on an AWS server than they do on your local machine, for example —
relative paths for file uploads work on localhost, but mess up on AWS. Also
file permissions are irritating to work with on AWS, but never an issue on
localhost (on a Mac). In such a scenario, is Docker for these issues? I
imagine I use Docker, make a "container" and setup everything properly in
that, and then just move it to AWS when I'm deploying?

~~~
mateuszf
You can also use Docker on AWS. Just use it as a target "runtime" for all your
environments.

~~~
arsalanb
So that would mean telling Docker to setup a container to model the
configuration on AWS on all my environments, correct?

------
brown9-2
Is there a technical reason why docker-machine on OS X doesn't set up
/var/run/docker.sock in a similar way? It sounds so simple when put this way
in the article.

------
abhv
So I imagine the solution is using xhyve to run a simple linux.

Why is the xhyve virtualization framework through low-level go-bindings better
than using VirtualBox for the same task?

~~~
biehl
It is more light-weight?

~~~
therealmarv
Yes. VirtualBox is emulating a whole PC including controllers for all internal
stuff like CPU, graphics, HDD etc. Where as xhyve is more like an interface
which can be used by VMs to access the native hardware indirectly.

------
tunesmith
My main problem with using Docker on OS X is that I have multiple OS X user
accounts - one for myself, one for my main client. And I ran into a bunch of
trouble trying to run boot2docker and dockermachine on both of them, it just
wouldn't work. Unfortunately I forget the details since I haven't had need to
use docker since then.

------
lbrindze
for me, using docker on my own workstation (OSX) makes it easy for me to test
deploy's to multiple machines quickly (even if these are only locally hosted
VMs). docker-machine facilitates that by allowing you to quickly spin up and
spin down virtual machines locally or in the cloud.

I can see advantages for running docker as a way of streamlining dev
environments, and keeping them consistent across team members, but by
automagicaly awaying the docker-machine env commands you have effectively lost
the most powerful facet of container technology.

Perhaps we would all do better if Docker's toolset docs were written in a way
to communicate these design decisions (their purpose, and how they
conceptually work behind the scenes)...

~~~
tlrobinson
If I understand, using this doesn't preclude you from using docker-machine, it
just gives you a default Docker installation, similar to what you'd get if you
installed the Docker daemon on your Linux workstation.

It might be neat if this were integrated into docker-machine though. Looks
like there's already a docker-machine plugin for xhyve
([https://github.com/zchee/docker-machine-driver-
xhyve](https://github.com/zchee/docker-machine-driver-xhyve)).

------
pikzel
I actually just use aliases, it feels like this DLite/dhyve is more of a hack.

------
ialex
Add this to your bash profile and it will feel simpler

function docker_activate() { eval $(docker-machine env $1) }

alias docker_activate=docker_activate

Then:

docker-machine start mymachine

docker_activate mymachine

------
vittore
Question, is there a homebrew package for DLite?

~~~
leipert
Hopefully soon:
[https://github.com/Homebrew/homebrew/pull/48460](https://github.com/Homebrew/homebrew/pull/48460)

------
sneak
Docker does run natively on OSX.

Just forward a port with ssh/socat/etc and set the environment variable
correctly to point to your build host that can run lxc.

There is so much over-engineering going on in this arena. :/

~~~
e40
There is no definition of "native" where your statement is true.

~~~
sneak
Containers don't run on osx, but docker isn't responsible for the containers
anyway - lxc is.

The "docker" program builds and runs natively under osx just fine, like any
other Go binary.

~~~
cyphar
Docker doesn't and hasn't used LXC for a long time. It uses libcontainer,
which is their own implementation of a container runtime. Even when Docker did
use LXC, the Docker daemon was required for management. The Docker daemon only
runs on GNU/Linux and Windows, so there is no sane definition of "native"
where the statement "Docker runs natively on OS X" is correct.

