Update (10/08/2020): For the most recent version of this resource, refer to the thread TrueCommand Auto-Update in the Resources section of the FreeNAS Community Forum.
Want to ensure that you’re always running the latest version of TrueCommand in a Docker container? Docker Compose is the enabler for automatic updates.
This technique I first used on resources for Nextcloud-OnlyOffice and Nextcloud-Collabora integration. It can be used in a more general sense with other Docker images to keep Docker containers up-to-date, but what better example to demonstrate it on in the FreeNAS forum than TrueCommand.
A check is done daily for a new version of the TrueCommand image. If a new version exists, it is downloaded and the TrueCommand container updated. The old image is then removed.
Outline of the steps
- Install TrueCommand using Docker Compose.
- Set up automatic updates.
Step 1: Install TrueCommand using Docker Compose
Install Docker Compose. This assumes you already have Docker installed on your Ubuntu host. If not, you may find Step 3 of the Nextcloud-OnlyOffice resource useful.
In the example below, note that TrueCommand data is stored in a nested folder under the home directory i.e. $HOME/truecommand/data
.
sudo docker run --detach -v "$HOME/truecommand/data:/data" -p 8080:80 -p 8081:443 --restart always --name=truecommand -e TZ=Australia/Perth ixsystems/truecommand
Run everything after sudo docker run
through Composerize to convert the command to Docker-Compose format.
Change to the TrueCommand folder cd $HOME/truecommand
. Create the Compose file nano docker-compose.yml
and paste in the output from Composerize.
version: '3.3' services: truecommand: volumes: - '$HOME/truecommand/data:/data' ports: - '8080:80' - '8081:443' restart: always container_name: truecommand environment: - TZ=Australia/Perth image: ixsystems/truecommand
Build and run TrueCommand with Compose sudo docker-compose up -d
.
Step 2: TrueCommand Automatic Updates
Make sure you’re in the TrueCommand folder cd $HOME/truecommand
. Create the update.sh script nano update.sh
and paste the following:
#!/bin/bash date cd "`dirname "$0"`" docker-compose pull docker-compose up -d docker image prune -f date echo
Make the file executable chmod +x update.sh
.
Next, we’re going to add a line, that takes the form below, to the system-wide crontab.
m h * * * /path/to/script >> /path/to/log 2>&1
Standard and error output will be appended to /path/to/log. By design, the log file will be placed in the TrueCommand folder as well, so:
/path/to/script = $HOME/truecommand/update.sh /path/to/log = $HOME/truecommand/update.log
However, we need to use the evaluated version of $HOME for the system-wide crontab. Make a note of what this is echo $HOME
.
For example:
For this example:
/path/to/script = /home/administrator/truecommand/update.sh /path/to/log = /home/administrator/truecommand/update.log
Note: If you’ve referred to environmental variables such as $HOME in the docker-compose.yml file, these will need to be replaced there as well.
Now, edit the system-wide crontab sudo crontab -e
and set up the cron job.
The script should be run at a time when it’s unlikely anyone will be using TrueCommand. In the example below, I’m checking for updates daily at half-past midnight.
30 0 * * * /home/administrator/truecommand/update.sh >> /home/administrator/truecommand/update.log 2>&1
If there isn’t an update when the job is run, a typical log entry will look something like the following:
If an update is available, the log entry will instead look more like this:
Comments