Docker on FreeBSD

Docker is now available of FreeBSD.
How cool is that?
And setup is so simple that it would be a shame not to try it out:

sudo pkg install docker-freebsd ca_root_nss  

As seems to be the case quite often with FreeBSD packages, after installing the package you get quite nice instructions on what to do next:

[fx@yotta /usr/home/fx]$ sudo pkg install docker-freebsd
Updating yotta.tln repository catalogue...  
Fetching meta.txz: 100%    264 B   0.3kB/s    00:01  
Fetching packagesite.txz: 100%   56 KiB  57.3kB/s    00:01  
Processing entries: 100%  
yotta.tln repository update completed. 209 packages processed.  
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:  
        docker-freebsd: 06252015
        go: 1.4.2,1

The process will require 142 MiB more space.  
23 MiB to be downloaded.

Proceed with this action? [y/N]: y  
Fetching docker-freebsd-06252015.txz: 100%    3 MiB   2.8MB/s    00:01  
Fetching go-1.4.2,1.txz: 100%   21 MiB  21.6MB/s    00:01  
Checking integrity... done (0 conflicting)  
[1/2] Installing go-1.4.2,1...
[1/2] Extracting go-1.4.2,1: 100%
[2/2] Installing docker-freebsd-06252015...
[2/2] Extracting docker-freebsd-06252015: 100%
Message for docker-freebsd-06252015:  
Docker requires a bit of setup before usage.

You will need to create a ZFS dataset on /usr/docker

# zfs create -o mountpoint=/usr/docker <zroot>/docker

And lastly enable the docker daemon  
# sysrc -f /etc/rc.conf docker_enable="YES"
# service docker start


Starting the docker service will also add the following PF rule:

nat on ${iface} from to any -> (${iface})

Where $iface is the default NIC on the system, or the value  
of $docker_nat_iface. This is for network connectivity to docker  
containers in this early port. This should not be needed in future  
versions of docker.  

So I did what the nice instruction said to do:

sudo zfs create -o mountpoint=/usr/docker zroot/docker  
sudo sysrc -f /etc/rc.conf docker_enable="YES"  
sudo service docker start  

It really is that simple.

So now, to run a Debian container, simply download and run it by doing:

sudo docker pull debian  

and then run a bash shell inside of Debian container

sudo docker run -t -i debian /bin/bash  


[fx@yotta /usr/home/fx]$ sudo docker run -t -i debian /bin/bash
root@:/# uname -a  
Linux  2.6.32 FreeBSD 11.0-CURRENT #0 r285684: Sun Jul 19 10:19:35 UTC 2015 x86_64 GNU/Linux  

One slight issue is that it is still experimental and some stuff does not seem to work.
For example in a Debian Wheezy container mostly everything segfaults:

[fx@yotta ~]$ docker run -t -t debian:wheezy /bin/bash
jail: /bin/bash: exited on signal 11  

stracing does not help because it does not work:

strace: test_ptrace_setoptions_for_all: PTRACE_TRACEME doesn't work: Function not implemented  

But other than that stuff works and it does not get much more simpler than that.
You get Docker + ZFS.
One reason less to run linux as your host os.