Profile pic of Tommy KuTommy Ku's Blog

Reading and thinking

Deploying Komga on FreeNAS jail

Posted on March 15, 2020

I’ve built myself a NAS using old parts and FreeNAS. Then I realized I can host a variety of services on my NAS such as Emby, Syncthing and duplicati with FreeNAS plugins out-of-the-box.

Compared to the wealth of containers available on Docker Hub, plugins on FreeNAS are somewhat lacking. However that doesn’t mean docker is the to-go option for running isolated services. Instead, jail came out of the box in FreeNAS while docker didn’t. Plus I couldn’t get RancherOS (a host-OS for docker) to run on a FreeNAS VM, so I gave up.

In this post I am going to walk you through how I deployed a manga-reading application Komga to my FreeNAS jail.

Creating a Jail

First locate the Jails section on the side menu of FreeNAS dashboard, then click ADD on the top right corner. Here fill in the Name, and choose a Release from the dropdown menu, then click NEXT.

Creating a Jail

There are 3 ways to set the IP addresses of the jail - VNET/NAT, DHCP or static IP.

With VNET/NAT you access your service via the same IP as your FreeNAS and some unused port.

With DHCP, you still access your services from unused ports but via an IP distributed by the DHCP server.

With static IP like below, I specify an IP address, subnet mask and default router to my home network router. If you find the default router field disabled, clicking some of the checkboxes will re-enable it. You can then edit the default router before unchecking the checkboxes.

Oh, feel free to check the Auto-start checkbox at the bottom as well.

Editing Jail properties

After saving and starting the jail, you will have a working jail with its own IP address and isolation. At this point it is not running service for you, so in the next part we will mount a ZFS folder to it and install Komga for you to read comics.

Deploying Komga to a jail

From the Jails page click on the arrow on the right of our Komga jail, then click Mount Points in the expanded panel. Here you can configure where in your pools do you want to make visible to the jail by mounting. Otherwise, the jail will see only files inside its own iocage dataset.

Komga jail in Jails page
Mounting folder to the jail

Komga requires Java to run which is not available. To install Java 11, start the jail and click Shell from the Jails page. In the resultant shell screen you have logged in to the jail’s shell, not to your FreeNAS host shell. Installing Java in the shell doesn’t make it available to the host OS.

# Jail Shell
# Developer of Komga recommends using openjdk11 over openjdk8 for better performance
pkg install openjdk11
Screen shown after installing java

As shown in the screenshot there are some post-installation steps required for Java. However we need to do them on the host-OS’s shell instead of inside the jail. Open the host OS shell from the left menu, then run the following commands.

# Host Shell
mount -t fdescfs null /mnt/{POOL NAME}/iocage/jails/Komga/root/dev/fd
mount -t procfs null /mnt/{POOL NAME}/iocage/jails/Komga/root/proc

Next return to the jail’s shell, and from /root download the latest version of Komga using fetch. Alternatively, you may download the file elsewhere and drop it into jail’s own dataset.

# Jail Shell

To quickly test whether Komga is working, start the Komga server from /root.

# Jail Shell
/usr/local/bin/java -jar ./komga-0.27.7.jar

Navigating to the webpage at port 8080 of your jail’s IP, you will see Komga’s login screen.

Komga login screen

You won’t be able to login at the moment because no account is created yet. Follow Komga’s installation instruction to get it up and running.

If you want to change some of the default config options, Komga’s configuration is stored in a file application.yml alongside the jar. A sample configuration file can be found in Komga’s documentation.

The last bit of this deployment is to make Komga start every time the jail is started. Navigate to /etc and create a file rc.local.


exec 2> /tmp/rc.local.log
exec 1>&2
set -x

cd /root
nohup /usr/local/bin/java -jar /root/komga-0.27.7.jar

exit 0

Lastly, make rc.local executable.

# Jail Shell
chmod +x /etc/rc.local

This way next time when you start the jail, Komga will automatically be started too.

More Information

This post was created with the help of the following pages:

You could also look at...