Recently I’ve been using FreeBSD for development, in part because I really like the experience of developing inside of jails. No, I’m not delinquent for tax evasion, what I mean is that FreeBSD provides something called a Jail , which I have found is a happy medium between a VM and a Linux container. Jails, like containers, use the host kernel, however, are less ephemeral than containers. Here’s how I created a container to run Apache for developing this blog. Note in the future I want to use a different web server, maybe something I develop in Rust.

FreeBSD Version: 13.0-RELEASE.

install a new jail to /root/jails/apache

bsdinstall jail /root/jails/apache

edit jail.conf

vim /etc/jail.conf

paste the following

apache {
  host.hostname = phobos;
  ip4 = inherit;                             # inherit the ip4 address from the host machine
  path = "/root/jails/apache";               # Path to the jail
  mount.devfs;                               # Mount devfs inside the jail
  exec.start = "/bin/sh /etc/rc";            # Start command
  exec.stop = "/bin/sh /etc/rc.shutdown";    # Stop command
}

start the jail called apache

sudo /etc/rc.d/jail onestart apache

invoke the default shell

sudo jexec apache /bin/sh

update, upgrade and install bash

pkg update; pkg upgrade; pkg ins bash

change the default shell to bash

chsh -s /usr/local/bin/bash root

exit current shell

exit

We can now use bash!

sudo jexec apache

I needed to run the following command on the host (not the jail) to give permissions to use raw_sockets. Without this, an ominous error message is displayed when in the Jail and using the interface, for example to ping. edit: This is only needed for certain network capabilities such as ping

jail -m name=apache allow.raw_sockets=1

install and start apache. After this, on the host machine you should be able to curl 192.168.0.1

pkg ins apache24; sysrc apache24_enable="yes"; service apache24 onestart