How to Use Docker on FreeBSD (and the Best Alternatives)

Docker has become the de facto standard for containerization on Linux systems. It provides developers with an easy and reproducible way to deploy applications. But if you’re a FreeBSD user like me, you’ve probably discovered that Docker isn’t natively supported. That’s because Docker relies heavily on Linux kernel features such as cgroups, namespaces, and UnionFS, which FreeBSD does not support directly.

So, what are our options? Can we still run containers on FreeBSD, or even Docker itself? The answer is yes—with some workarounds and native alternatives.

In this blog post, we will walk you through several approaches:


⚠️ Why Docker Doesn’t Run Natively on FreeBSD

Docker was built specifically for the Linux kernel. It depends on:

  • Linux control groups (cgroups)
  • Namespaces
  • AUFS/OverlayFS
  • A running Docker daemon

FreeBSD uses different mechanisms, such as jails and ZFS. Because of this incompatibility, Docker can’t run on FreeBSD without a Linux layer. However, that doesn’t mean you’re out of luck.


✅ Option 1: Use Podman – A Docker-Compatible Alternative

Podman is a daemonless container engine that offers a command-line interface similar to Docker. It’s available in FreeBSD’s package repository and works quite well for many use cases.

🔧 Installing Podman on FreeBSD

pkg install podman

Start the Podman service:

service podman start

Now you can use it just like Docker:

podman pull alpine
podman run -it alpine sh

Podman runs rootless containers, which means better security, but some Docker features like Docker Compose or privileged containers might not be fully supported.


🖥️ Option 2: Run Docker Inside a Linux VM

If you absolutely need full Docker functionality, the best solution is to run Docker inside a virtual machine. You can do this using FreeBSD’s native hypervisor bhyve, or with VirtualBox.

A. Using bhyve and vm-bhyve

  1. Install the required packages:
pkg install vm-bhyve grub2-bhyve
  1. Initialize the environment:
zfs create -o mountpoint=/vm zroot/vm
vm init
vm switch create public
  1. Download a Linux ISO (e.g., Ubuntu), and create the VM:
vm iso https://releases.ubuntu.com/22.04/ubuntu-22.04-live-server-amd64.iso
vm create ubuntuvm
vm install ubuntuvm ubuntu-22.04-live-server-amd64.iso
  1. After installing Ubuntu, log into the VM and install Docker:
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Now you have a full Linux environment running Docker within FreeBSD.

B. Using VirtualBox

If you prefer a GUI solution, VirtualBox works well on FreeBSD:

pkg install virtualbox-ose

After installation, create a Linux virtual machine (e.g., Ubuntu, Alpine), then install Docker inside it as shown above.


🔐 Option 3: Use FreeBSD Jails with BastilleBSD

FreeBSD has its own native containerization technology: jails. They are extremely lightweight and secure. You can manage jails easily with a tool like BastilleBSD.

🔧 Installing BastilleBSD

pkg install bastille
sysrc bastille_enable=YES
service bastille start

📦 Bootstrap a FreeBSD Release

bastille bootstrap 13.2-RELEASE

🛠️ Create and Start a Jail

bastille create myjail 13.2-RELEASE 10.0.0.10
bastille start myjail
bastille console myjail

Now you’re inside a FreeBSD jail where you can run isolated applications.

While this isn’t Docker-compatible, it’s extremely efficient and secure for server deployments.


📝 Summary Table

MethodDocker-CompatibleFreeBSD NativeIdeal Use Case
Podman✅ Partial✅ YesDevelopment, rootless containers
Linux VM (bhyve)✅ Full❌ NoFull Docker support, CI/CD setups
VirtualBox✅ Full❌ NoDesktop Docker environment
BastilleBSD❌ No✅ YesSecure, lightweight FreeBSD jails

🤔 Final Thoughts

While Docker doesn’t run natively on FreeBSD, you still have powerful and flexible options depending on your use case:

  • Want to run containers like Docker? Try Podman.
  • Need full Docker functionality? Use a Linux VM with bhyve or VirtualBox.
  • Want lightweight, secure FreeBSD-native containers? Go with jails and BastilleBSD.

Each method has its strengths and trade-offs.

Post Comment

You May Have Missed