Last Updated: October 18, 2020
·
12.88K
· avgp

Lightweight dev environment with fig & boot2docker on OSX

Vagrant is cool, but heavy. Can I use docker? Answer: Yes, with fig

Vagrant is cool, because it allows easy setup of development VMs to work in. But VMs tend to be quite heavy and running 20 services within 20 VMs on your Macbook will definitely keep you warm in the winter but may not help your productivity.

This is exactly where fig comes in: It allows you to configure a set of docker containers and their links between each other and then run each service within a docker container.

This is a very lightweight approach and it's perfectly fine to run 20 containers on your machine.

Docker and OSX: Boot2Docker and its problems

Now Docker is cool and all - but I know most of you are working on OSX. Often enough I'm doing that, too. But Docker is a Linuxcontainer tool. No OSX. Sad puppy.... but fear not!

Boot2Docker is a cool (and now recommended) way of getting Docker onto OSX: It starts a single, small VM to run Docker and the containers inside. Yay!

But there's bugs and road blocks...

The issue of fig, shared volumes and Boot2Docker

Unfortunately the way fig works (see their getting started guide, for example) is by sharing the directory containing your code with the docker container (mounting it as a volume). That works perfectly fine when you're on a Linux machine and Docker runs directly on it. But here, docker can only mount from the filesystem of your Boot2Docker VM.... which is not where your source code lives.

So here's the first hoop to jump - after installing boot2docker you should get a custom image for boot2docker that contains the guest additions of Virtualbox like this:

$ cd ~/.boot2docker
$ curl http://static.dockerfiles.io/boot2docker-v1.0.0-virtualbox-guest-additions-v4.3.12.iso > .boot2docker.iso
$ boot2docker init
$ VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
$ boot2docker up

(I found that solution after some googling at https://github.com/orchardup/fig/issues/26)

Once the machine is up, we need to mount the shared folder inside the VM:

$ boot2docker ssh "sudo modprobe vboxsf && mkdir -v -p /Users && sudo mount -v -t vboxsf  -o uid=0,gid=0 home /Users"

That's a small variation from the issue thread I linked above: We're explicitely setting the uid and gid, so it becomes accessible.

Cool.

The last pitfall: port forwarding

Care shall be taken with port forwards... the server you started is in another castle, Mario!

As "localhost" refers to the boot2docker VM, you have to use the private IP of the boot2docker VM and you get that from:

$ boot2docker ip

Happy developing!

7 Responses
Add your response

Thanks! This is exactly why I write these tips :)

over 1 year ago ·

I run Docker on Ubuntu via Vagrant on OSX and start the whole circus running 'vagrant up'

over 1 year ago ·

It helped me a lot, thanks! But the "." in ".boot2docker.iso" is a typo, at least I had to omit it to make it work.

over 1 year ago ·

Thank you. Could you also please remove that . so that it can be useful to others?

over 1 year ago ·

You also have to add "sudo" prior to mkdir if you want a different directory

over 1 year ago ·

One small note regarding a subtle problem with running servers in the containers - at least in the Python apps I've done/seen - they need to be configured on host 0.0.0.0 to answer their sockers. HTH, Mark

over 1 year ago ·

With the new version of boot2docker it's seem I had trouble with "boot2docker ssh "sudo modprobe vboxsf && mkdir -v -p /Users && sudo mount -v -t vboxsf -o uid=0,gid=0 home /Users". After some test I found that the problem come from "curl http://static.dockerfiles.io/boot2docker-v1.0.0-virtualbox-guest-additions-v4.3.12.iso > .boot2docker.iso". The only thing to change is to remove ".boot2docker.iso" by "boot2docker.iso"

over 1 year ago ·