Post

Migrating TrueNAS Scale apps to docker compose part 2

I use syncthing to copy data to a couple remote synology servers and my relatives house which provides an off-site copy of my important data, following the 3-2-1 backup strategy.

Export existing application as a docker-compose file

The first step in migrating syncthing to docker managed by portainer is converting the config to a docker compose file. To help facilitate this work, I utilized this awesome docker-autocompose project. By SSHing into my TrueNAS server I could run the following as root to generate a docker-compose file off the running app.

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/red5d/docker-autocompose ix-sync-syncthing-1

The output will create a yaml file that can be saved as your docker-compose file. Below is a cleaned up version of the output provided by the docker-autocompose project.

Some differences:

  • I copied the existing syncthing app config from /mnt/.ix-apps/app_configs/syncthing to my own, defined location of /mnt/apps/services/syncthing/.
  • I setup rsync and snapshots to backup my new app config location of /mnt/apps/services to my backup server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
version: "3.6"

services:
  syncthing:
    container_name: "syncthing"
    image: "syncthing/syncthing:latest"
    restart: always
    entrypoint:
      - "/bin/entrypoint.sh"
      - "/bin/syncthing"
    environment:
      - "TZ=Etc/UTC"
      - "STGUIADDRESS=0.0.0.0:8384"
      - "UID=1001"
      - "GID=568"
      - "GROUP_ID=568"
      - "STNOUPGRADE=true"
      - "PGID=568"
      - "USER_ID=1001"
      - "PUID=1001"
      - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      - "HOME=/var/syncthing"
      - "STHOMEDIR=/var/syncthing/config"
    logging:
      driver: "json-file"
      options: {}
    networks:
      - "sync_default"
    ports:
      - "0.0.0.0:8384:8384/tcp"
      - "0.0.0.0:20978:22000/tcp"
      - "0.0.0.0:20979:22000/udp"
    volumes:
      - "/mnt/apps/services/syncthing/var/:/var/syncthing"
      - "/mnt/storage:/storage"
networks:
  sync_default:
    name: "sync_default"

I then added the docker-compose yaml file to my docker-services git repo.

Deploy portainer stack

Now that I have converted my syncthing application to a docker-compose file, I can create a portainer stack and link it directly to my gitlab server. This feature requires portainer business edition, which is free for up to 3 nodes.

I created a syncthing stack and used the Repository build method. I added my gitlab credentials, path to the respository and the docker-compose yaml file name.

Once ready, click Deploy stack to deploy the stack onto the remote truenas server.

Success! Now I have a application managed by code that I can then look into integrating in some GitOps process to keep updated. This will be a future enhancement.

This post is licensed under CC BY 4.0 by the author.