Richard Bucker

New and improved Docker 1.3.0

Posted at — Oct 17, 2014

So this was a lot of fun. At first I was thinking that I was going to leave my Docker development to my cloud servers and my work laptop. But that with the latest Docker 1.3.0 release and the associated boot2docker and fig projects I had to install it on my personal laptop.First some descriptions:Docker - an open platform for distributed applicationsboot2docker - lightweight linux distribution that runs inside a VirtualBox virtual machine.fig - configuration and orchestration for a single-host deploymentSecond a small piece of advice. Fig and boot2docker are meant for development although fig might work in environments other than boot2docker. There are a number of clues that the docker team and very early adopters (fig was recently acquired by the docker company) have left for the rest of us:Your build or makefile should use a container to perform the build. Eat your own dogfood. Both fig and boot2docker use a docker container to create the executable tools and boot2docker it’s iso image that is later used by the user to build apps.Here is a short list of steps that I went through to deploy the tools on my personal Yosemite OSX laptop.Download and install the appsboot2dockercurl https://github.com/boot2docker/osx-installer/releases/download/v1.3.0/Boot2Docker-1.3.0.pkgnow you have to perform the standard installationfigcurl -L https://github.com/docker/fig/releases/download/1.0.0/fig-`uname -s-uname -m &gt; /usr/local/bin/fig; chmod +x /usr/local/bin/fig</i></li></ul></ul></ul></div>Now you need an application. Let's start with the fig.yml file:<br /><div><blockquote class="tr_bq"><span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><span style="font-size: x-small;">hello:</span></span><span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; &nbsp; &nbsp; &nbsp; image: busybox</span><span class="s1" style="background-color: white;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">&nbsp; &nbsp; &nbsp; &nbsp; command: /bin/echo 'Hello world'</span></span></blockquote><div class="p1"><span class="s1"><span style="font-family: Times, Times New Roman, serif;"><span style="background-color: white;">This is an over simplified and small application. It's purpose to to just print the </span><span style="background-color: #cccccc;">hello world</span><span style="background-color: white;"> message.</span></span></span></div><div class="p1"><span class="s1"><span style="font-family: Times, Times New Roman, serif;"><span style="background-color: white;"><br /></span></span></span></div><div class="p1"><span class="s1"><span style="font-family: Times, Times New Roman, serif;"><span style="background-color: white;">With the fig.yml file in the current folder then let's execute the first docker commands via the tools.</span></span></span></div><div class="p1"><span class="s1"><span style="font-family: Times, Times New Roman, serif;"><span style="background-color: white;"><br /></span></span></span></div><div class="p1"></div><ul><li><span style="font-family: Times, 'Times New Roman', serif;">initialize boot2docker</span></li><ul><li>boot2docker init</li></ul><li>start the boot2docker VM instance</li><ul><li>boot2docker start</li></ul><li>capture the docker config so that the local tools can communicate with the VM host instance</li><ul><li>boot2docker shellinit</li></ul><li>run the application via fig</li><ul><li>fig run hello</li></ul></ul><div>And that's it. Note that in the fig.yml file I selected the busybox linux distro. This is one of the smallest and docker-trusted distros available with enough features to run the hello application. The command is self explanatory.</div><div><br /></div><div>** this example is not complicated enough to warrant a makefile or even a repo of it's own. Just know that this is what you'll when you run the <i>run</i>&nbsp;command for the first time:</div><br /><blockquote class="tr_bq"><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ fig run hello</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Pulling image busybox...</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">df7546f9f060: Pull complete</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">df7546f9f060: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">df7546f9f060: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">df7546f9f060: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">df7546f9f060: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">511136ea3c5a: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">511136ea3c5a: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">511136ea3c5a: Already exists</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">busybox:ubuntu-12.04: The image you are pulling has been verified</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">0dfaa2625e19: Pull complete</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">d415c60e5ea3: Pull complete</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">busybox:ubuntu-14.04: The image you are pulling has been verified</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">25fb2184d4af: Pull complete</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">d940f6fef591: Pull complete</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Status: Downloaded newer image for busybox</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Hello world</span></span></blockquote><div class="p1"></div><div>Notice that fig executed all of the necessary docker commands to prepare the environment and eventually executed the command much like this:</div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">docker run busybox /bin/echo 'hello world'</span></blockquote><div>One reason I selected busybox was because of it's size. I had also tried ubuntu but that was pretty big. And when I tried scratch there was not enough gusto in the base OS to run the echo command.</div><div><br /></div><div>The second run command will result in this:</div><div><blockquote class="tr_bq"><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ fig run hello</span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></span><span class="s1"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Hello world</span></span></blockquote><div class="p1"></div></div><div>Notice that fig/boot2docker and docker itself did not need to re-download or re-build the environment. The container simply ran and produced output.</div><div><br /></div><div>The default size of the boot partition is 40GB, however, I needed a bigger partition for my project. Here is the cheatsheet of the commands I executed:</div><div><ul><li><span style="font-family: Courier New, Courier, monospace;">boot2docker destroy</span></li><li><span style="font-family: Courier New, Courier, monospace;">boot2docker --disksize=80000 init</span></li><li><span style="font-family: Courier New, Courier, monospace;">boot2docker start</span></li><li><span style="font-family: Courier New, Courier, monospace;">boot2docker shellinit</span></li><li><span style="font-family: Courier New, Courier, monospace;">boot2docker ssh</span></li><li><span style="font-family: Courier New, Courier, monospace;">df -h</span></li></ul><div>The results of the 'df' command should indicate that the primary partition is 80GB. (longer <i>init</i>&nbsp;and <i>start</i>&nbsp;command execution times)</div></div><div><br /></div><div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$ df -h</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Filesystem &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Size &nbsp; &nbsp; &nbsp;Used Available Use% Mounted on</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">rootfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.8G &nbsp; &nbsp;204.6M &nbsp; &nbsp; &nbsp;1.6G &nbsp;11% /</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1.8G &nbsp; &nbsp;204.6M &nbsp; &nbsp; &nbsp;1.6G &nbsp;11% /</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">tmpfs &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1004.2M &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; 1004.2M &nbsp; 0% /dev/shm</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/dev/sda1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;75.8G &nbsp; &nbsp; 65.6M &nbsp; &nbsp; 71.9G &nbsp; 0% /mnt/sda1</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cgroup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1004.2M &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; 1004.2M &nbsp; 0% /sys/fs/cgroup</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">none &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 55.4G &nbsp; &nbsp; 30.7G &nbsp; &nbsp; 24.7G &nbsp;55% /Users</span></div><div><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">/dev/sda1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<b style="background-color: #fce5cd;">75.8G</b> &nbsp; &nbsp; 65.6M &nbsp; &nbsp; 71.9G &nbsp; 0% /mnt/sda1/var/lib/docker/aufs</span></div></div><div><br /></div><div>Capture the boot2docker host IP address with this command. 'shellinit' has some use but this is not it.</div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">export D_HOST=boot2docker ip 2> /dev/null`That’s all there is for now. My next post might include volumes and links.UPDATE: I forgot to add that the boot2docker host uses ntpclient and other than the first init… subsequent ‘start’ commands cause the host to sync the time immediately. There is also a timer running on the host to periodically fix timeshift. Sadly, when putting my laptop to sleep the clocks can be way off. So I usually stop/start my environment when I’m not using it. I’m not sure yet but this might have some other benefits like longer battery life.