Install docker on FreeBSD

This is going to be a quick tutorial that’ll show you how to set up docker on a FreeBSD system. Docker, as you’re probably familiar with, is a utility that alleviates making, deploy, and launching software programs by compiling it into lightweight, executable packages called containers. By condensing an application into a package, the developers create a standalone container that comes with all the libraries and dependencies included. This makes the distribution much easier for the devs, as the containers allow the applications to work on various Linux platforms.

As of yet, docker isn’t supported for the FreeBSD operating system, so there’s no way you can use docker on FreeBSD, natively at least. Several attempts have been made to build the docker source up for FreeBSD, but none that I could find yielded any substantial results. This is likely because FreeBSD lacks some of Linux’s features, such as namespace and cgroups that aren’t yet a part of FreeBSD kernel.

So that leaves us with one option only: using a virtual machine. So we’ll use virtualbox in this tutorial to fire up a Linux VM in FreeBSD and use docker within it.

Step 1: Install docker client and virtual machine in FreeBSD

To install both docker client and virtual machine along with virtual box all in one command, type the following into the shell and hit enter:

$ sudo pkg install docker docker-machine virtualbox-ose

The reason why we’re setting up docker-machine with the virtual box is that it facilitates management for Docker hosts. With a docker-machine, you can create servers and install docker on each of them, and also configure each individually.

Step 2: Load the vboxdrv kernel module

With virtualbox installed on your system, load the vboxdrv kernel module. To do this and add your user account to the vboxusers group, you’ll need to run the following command:

$ sudo pw groupmod vboxuser -m <username>

Once the command executes, you’ll be able to use vbox. You can use virtual machines after restarting your system.

Step 3: Creating VirtualBox hosts

Use the command below to create a Virtualbox host:

$ docker-machine create -d virtualbox default

To see every host current on your system.

$ docker-machine ls

With a new virtual box host in place, we should set the VM parameters to communicate with the docker client. Use the command below:

$ eval "$(docker-machine env default)"

Then copy-paste this command to the .bashrc/.zshrc file, and you’re all set to use docker on FreeBSD.

Why go through all this trouble?

Surely there has to be an easier way to run docker, one that doesn’t need the use of virtual machines?

Well, no. As of yet, this is the only way to get docker up and running on a FreeBSD system, because as mentioned earlier, FreeBSD doesn’t have the support for some of the elements that are crucial to docker’s operation.

Then why not use an alternative to docker? I’ve heard rkt is a much better alternative to docker, and it runs on FreeBSD!

Sure, there are many FreeBSD alternatives to docker that are better, if not just as good. The thing is: most people are familiar with docker, and it’s rather daunting to shift platforms completely for some users. Another reason is the lack of instructional material for rkt, so those new to the containerization software would opt for docker instead of its FreeBSD alternatives.


That’s it for this tutorial. Hopefully, you’re now able to use docker on FreeBSD with the box.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.