搜尋此網誌

2026年4月30日 星期四

Raspberry Pi 運行 Firefly III Container

緣起:


    現在想仔細紀錄自己的收支,請 gpt 提供可用的工具,我最後選了 Firefly III。我現在偏愛這種 Web 專案,只要有瀏覽器就能存取,不分裝置跟作業系統的種類,而且更棒的事,它們都會提供 Docker Image。我的 Pi 跟手機有用 zero-tier 連上同個網路,所以在外時也能透過 zero-tier vpn 來存取



Docker Compose:


    這篇的重點是怎麼讓它跑起來,雖然官方有提供現成的 Docker Compose 範例檔,但如果想讓 Firefly III Container 跑在 Raspberry Pi 上的話,要自己做些微調

    官方教學,下載 compose file,還有兩個設定檔要下載, .env 跟 .db.env

    首先是 docker-compose.yml 檔

services:
  app:
    image: fireflyiii/core:latest
    hostname: app
    container_name: firefly_iii_core
    restart: always
    volumes:
      - ./firefly_iii_upload:/var/www/html/storage/upload
    env_file: .env
    networks:
      - firefly_iii
    ports:
      - 8181:8080
    depends_on:
      - db
  db:
    image: postgres:latest
    hostname: db
    container_name: firefly_iii_db
    restart: always
    env_file: .db.env
    networks:
      - firefly_iii
    volumes:
      - ./firefly_iii_db:/var/lib/postgresql
  cron:
    #
    # To make this work, set STATIC_CRON_TOKEN in your .env file or as an environment variable
    # The STATIC_CRON_TOKEN must be *exactly* 32 characters long
    # Use this URL for inspiration: https://www.random.org/strings/?num=1&len=32&digits=on&upperalpha=on&loweralpha=on&unique=on&format=html&rnd=new
    #
    image: alpine
    restart: always
    container_name: firefly_iii_cron
    env_file: .env
    command: ["sh", "-c", "apk add tzdata && \
      (ln -s /usr/share/zoneinfo/$$TZ /etc/localtime || true) && \
      echo \"0 3 * * * wget -qO- http://app:8080/api/v1/cron/$$STATIC_CRON_TOKEN;echo\" \
      | crontab - && \
      crond -f -L /dev/stdout"]
    networks:
      - firefly_iii
    depends_on:
      - app

#volumes:
#   firefly_iii_upload:
#   firefly_iii_db:

networks:
  firefly_iii:
    driver: bridge


    這邊列我自己修改的地方

    第 8 行:從 volumes 改成使用當前路徑下的資料夾。

    第 13 行:原本映射到 80 port,改成 8181。

    第 17 行:原本是使用 MySQL,改用 postgreSQL。它官方文件有提到,如果你是用 arm/v7 (Raspberry pi 這類的) 電腦的話,推薦使用 postgreSQL


    第 25 行從 volumes 改成使用當前路徑下的資料夾。要注意 postgresql container 的資料路徑是 /var/lib/postgresql。

    第 46~48 行:volumes 用不到,所以就註解了。

    我從這個 docker compose 檔學到,可以像 21 行那樣用 env_file 來指定環境變數檔。那個 cron 的話,好像是跟自動排程有關的,我就留著,說不定之後會用上。

    再來是 .db.env,把 MySQL 有關的刪掉,然後 PostgreSQL 的部份解除註解,修改 POSTGRES_PASSWORD 值。

POSTGRES_USER=firefly
POSTGRES_DB=firefly
POSTGRES_PASSWORD={你的PostgreSQL 密碼}

    最後是 .env 檔,這檔案有點長,302 行,大部份的設定我都沒動,這裡就只列修改的部份

# If you are a fancy linux nerd like me, use this command:
#
# head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c 32 && echo
#
#
APP_KEY={一組長度為32個字元的Token}

    第 27 行:給 cron container 使用的 token (參考 docker compose 檔 27~31 行),它有好心地提供一組網址,可産生隨機、符合要求的 token。

# Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III
# For other database types, please see the FAQ: https://docs.firefly-iii.org/references/faq/install/#i-want-to-use-sqlite
# If you use Docker or similar, you can set these variables from a file by appending them with _FILE
# Use "pgsql" for PostgreSQL
# Use "mysql" for MySQL and MariaDB.
# Use "sqlite" for SQLite.
DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=firefly
DB_USERNAME=firefly
DB_PASSWORD={你的PostgreSQL 密碼}
# leave empty or omit when not using a socket connection
DB_SOCKET=

    第 94 行:改成 pgsql
    第 96 行:postgreSQL 的 port 是 5432
    第 99 行:密碼要跟你 .db.env 檔的 POSTGRES_PASSWORD 值一樣

    都修改好後,terminal 輸入 docker compose up 的指令,你的個人 Firefly III 就能正常運行了。

沒有留言:

張貼留言