Install Unifi in Docker

By | February 8, 2019

Containerizing Unifi has the benefit of OS updates not impacting you. Gone are “oh shoot, I updated Java and now UniFi won’t start because it wants some other version” problems.

$ sudo apt install docker.io
$ sudo docker run -d \
    --restart=unless-stopped \
    --net=host \
    --name=unifi \
    -e TZ='Australia/Perth' \
    -e RUNAS_UID0=false \
    -e UNIFI_UID=1001 \
    -e UNIFI_GID=1001 \
    -v /var/docks/unifi:/unifi \
    jacobalberty/unifi:stable

When you want to upgrade to new version, type:

$ docker pull jacobalberty/unifi:stable
$ docker stop unifi
$ docker rename unifi unifi.save
<same command as above to create new container>
<test, make sure it's all good>
$ docker rm unifi.save

You’ll likely want to clean up unused images. docker images to see. You’re likely going to remove images other than the latest with docker rmi <image-id>.

Upgrade Script

#!/bin/bash
set -ex

out=$(docker pull jacobalberty/unifi:stable)

if [[ $out != *"up to date"* ]]; then
if [ ! "$(docker ps -q -f name=unifi)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=unifi.save)" ]; then
docker rm unifi.save
fi

docker stop unifi
docker rename unifi unifi.save
docker update --restart=no unifi.save
docker run -d \
--restart=unless-stopped \
--net=host \
--name=unifi \
-e TZ='Australia/Perth' \
-e RUNAS_UID0=false \
-e UNIFI_UID=1001 \
-e UNIFI_GID=1001 \
-v /var/docks/unifi:/unifi \
jacobalberty/unifi:stable
docker image prune -f
fi
fi

One thought on “Install Unifi in Docker

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.