Over the last couple of months I came across multiple questions on how to run Docker on FreeBSD. Usually the discussion ends up
Jails as the native FreeBSD solution (which it is). But often then not outside requirements dictate the use of the Docker container solution.
Not to repeat the discussion, and there are plenty of already, but if you are looking for segregation of a set of processes
with containers and you don’t rely on any
hubs to do so, Jails most likely will fit the bill.
But this post is about the cases you can not or want to. The idea outlined here is not new and reflects
the setup on FreeNAS and in a wider sense how it is done on Windows and OSX.
To give you an idea what we are going to do:
- Setup FreeBSD with Bhyve (which means you need a machine capable todo so. Check the FreeBSD manual )
- Install Debian 9 onto a newly created VM.
- Install Docker there.
- Open up Docker remote API.
- Install Portainer to manage containers from the outside (web).
Key thing to highlight is that there is no
docker command available on FreeBSD. So running CLI commands
will need you to login into the Debian VM or use the web interface.
The FreeBSD pkg repo has a package called
Docker-compose which work great with the docker daemon running in the VM.
DOCKER_HOST env to the ipaddress and port eg
192.168.0.21:2376. This gives a native interface with docker from FreeBSD.
I assume you have FreeBSD running on your machine with Bhyve enabled and ready to go.
Personally I use the FreeBSD package
vm-bhyve to run VMs on Bhyve. Install it via the
pkg command. You know the drill.
Please follow the setup guide on Github.
Make sure to setup the virtual switch.
$ sudo vm create -t debian -s 20G debian
Edit the generated debian.conf file in the directory (eg
/zrt/vm/debian) holding the VM files and add more memory and cpu
to fit your needs.
$sudo vm iso https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.6.0-amd64-netinst.iso
sudo vm install debian debian-9.6.0-amd64-netinst.iso
Check that the
tap0 interface opened by Bhyve is connected to the Bhyve bridge.
Console into the VM and complete the typical Debian installation. If the installer is unable to
obtain an IP address then check the network settings (bridge and vm-bhyve switch)
$ sudo vm console debian
After completing the installation you should have a minimum Debian installation.
Add additional packages to make life easier:
$ apt-get install vim net-tools
Coming from BSD the lack of
netstat is quite painful.
Docker is now fully configure and the hello-world should work:
$ docker run hello-world
I assume you want to use a web frontend but you can as easily run Docker commands from within the VM.
Login via ssh or via
vm console debian
Portainer is a web interface for Docker with a nice dashboard and logging capabilities.
Installation if pretty straight forward:
Run these commands from inside the VM:
Get the VM’s IP address:
$ ip address
And navigate to port 9000 to finish the install of Portainer. You could use a local socket connection but then every link in Portainer is
0.0.0.0 where when you would choose the external environment and use the IP address these mappings would work like you would expect.
These settings can be changed at
This is the rough outline of how to get Docker running on FreeBSD.
Is it wise to open the API?
Well you should secure that port with firewall rules
in a production setting.
- Added info about the docker pkg.