If you follow my blog you probably already know I’ve been playing around with docker and CoreOS from sometime now. Even though I have several KVM instances of CoreOS running on my home server, I felt the need to have a VM on my mac to learn more stuff on the go.
I’ve spined up a CoreOS vagrant and started having some fun.
Yeah, yeah, I know there’s boot2docker, that abstracts everything in a easy install, so why have all the fuss of getting CoreOS up and running? Because I believe CoreOS will be the building block of the future of containerisation. And the time for learning about it, is now!
I started by building my first docker image from scratch. Things escalated quite quickly and I ended up with an awesome chef cookbook testing setup, almost by accident :p
Hoping you might find my setup useful as it’s been for me, here’s a blog post explaining how to get it up and running.
For comparison purposes, these were my software versions when I wrote this post:
|Mac OS X||10.9.5|
Lets get down to business
Download and install the following packages:
Install the test-kitchen gem and its docker driver
Clone CoreOS vagrant config and spin it up
Enable remote API for docker
By default, CoreOS has the docker API listening on a local socket. As we’re going to manage containers remotely we’ll need to make docker available on a TCP socket (more info about this here).
On the CoreOS box create the following file
/etc/systemd/system/docker-tcp.socket and add this:
Then enable the new socket:
And logout from the CoreOS box.
Adding a friendly name
On your host, add a friendly hostname for your CoreOS instance
Export the new docker endpoint and test it out
You should see something like this:
Note: If you can’t reach the coreos guest via 172.17.8.101 it might be related to an overlapping route on your host.
You’ll need to add a new route, here’s an example:
route -vn add -net 172.17.8.0/24 -interface vboxnet1
That’s it, let the cooking begin
I’ve made available on github an example so you can start testing your setup right away.
This will download a docker image I’ve built from the public docker hub, start a new container, push an example cookbook into it, generate a runlist and do a chef-solo run with that runlist, all like magic.
If all went according to plan, you just converged your first container testing an useless cookbook. So give yourself a pat on the back, good job!
Now you can go on and build awesome cookbooks, fully tested on your new shiny setup, enjoy!
Pro-tip: vim + syntastic + rubocop + foodcritic = another #epic combo!