Déployer le Hub Watchflare avec Docker
Déployez le Hub Watchflare avec Docker Compose. Fichier Compose complet, génération des secrets, TimescaleDB, volumes de données et bind mounts.
Le Hub tient dans une image Docker : le tableau de bord est déjà dedans. À côté, un conteneur TimescaleDB garde les données.
Astuce
Première fois ? Le démarrage en 5 minutes suffit pour être opérationnel.
Remarque
Pas Docker ? Le Hub s’installe aussi en binaire systemd sous Linux.
Prérequis
- Docker Engine 20.10+
- Docker Compose v2+
- Deux ports ouverts : 8080 (HTTP) et 50051 (gRPC)
1. Créer le fichier Compose
Enregistrez ce fichier sous docker-compose.yml dans un dossier dédié :
services:
watchflare:
image: ghcr.io/watchflare-io/watchflare:latest
container_name: watchflare
ports:
- "${HUB_PORT:-8080}:8080"
- "${GRPC_PORT:-50051}:50051"
environment:
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_USER=${POSTGRES_USER:-watchflare}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
- POSTGRES_DB=${POSTGRES_DB:-watchflare}
- POSTGRES_SSLMODE=disable
- GRPC_PORT=${GRPC_PORT:-50051}
- JWT_SECRET=${JWT_SECRET:?Set JWT_SECRET in .env}
- NOTIFICATION_ENCRYPTION_KEY=${NOTIFICATION_ENCRYPTION_KEY:?Set NOTIFICATION_ENCRYPTION_KEY in .env}
- TLS_MODE=${TLS_MODE:-auto}
- TLS_PKI_DIR=/var/lib/watchflare/pki
- GRPC_TIMESTAMP_WINDOW=${GRPC_TIMESTAMP_WINDOW:-300}
- ENV=production
- COOKIE_SECURE=${COOKIE_SECURE:-}
- COOKIE_DOMAIN=${COOKIE_DOMAIN:-}
- TRUSTED_PROXIES=${TRUSTED_PROXIES:-127.0.0.1,::1}
volumes:
- pki_data:/var/lib/watchflare/pki
depends_on:
postgres:
condition: service_healthy
networks:
- watchflare_net
restart: unless-stopped
postgres:
image: timescale/timescaledb:latest-pg16
container_name: watchflare-postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-watchflare}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-watchflare}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-watchflare}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- watchflare_net
restart: unless-stopped
volumes:
pgdata:
driver: local
pki_data:
driver: local
networks:
watchflare_net:
driver: bridge 2. Créer le fichier .env
Générez les trois secrets. NOTIFICATION_ENCRYPTION_KEY chiffre, au repos, les identifiants SMTP et les URL des canaux. Posez-la tout de suite, même sans notifications pour l’instant : Compose refuse de démarrer sans.
printf "POSTGRES_PASSWORD=%s\nJWT_SECRET=%s\nNOTIFICATION_ENCRYPTION_KEY=%s\n" \
"$(openssl rand -base64 32)" \
"$(openssl rand -base64 32)" \
"$(openssl rand -base64 32)" > .envRemarque
Sous macOS, prenez l’onglet Linux : openssl est là par défaut.
3. Lancer les conteneurs
$ docker compose up -d [+] Running 3/3 ✔ Network watchflare_watchflare_net Created ✔ Container watchflare-postgres Started ✔ Container watchflare Started
Vérifiez que les deux conteneurs tournent :
docker compose ps Le Hub répond sur http://your-host:8080.
Persistance des données
Deux volumes Docker nommés :
| Volume | Contenu |
|---|---|
pgdata | Base PostgreSQL (métriques, hôtes, paquets, utilisateurs) |
pki_data | CA TLS et certificat serveur (générés au premier démarrage) |
Docker s’occupe des volumes : rien à chown. Les données restent après un redémarrage ou une mise à jour d’image.
Bind mounts
Par défaut, Docker range pgdata et pki_data où il veut. Pour les mettre à un chemin précis sur la machine (sauvegarde, inspection, migration), remplacez l’un, l’autre, ou les deux par un bind mount vers un dossier local.
Chacun se remplace indépendamment.
Données PKI (Hub, UID 65532)
Le conteneur Hub tourne sous l’UID 65532. Le dossier PKI doit lui appartenir avant le démarrage :
mkdir -p /your/path/pki
sudo chown -R 65532:65532 /your/path/pki Puis dans docker-compose.yml :
# Remplacer :
- pki_data:/var/lib/watchflare/pki
# Par :
- /your/path/pki:/var/lib/watchflare/pki Retirez pki_data de la section volumes: en bas du fichier s’il ne sert plus.
Données de la base (TimescaleDB, UID 70)
Le conteneur TimescaleDB lance PostgreSQL sous l’UID 70. Le dossier de données doit lui appartenir :
mkdir -p /your/path/pgdata
sudo chown -R 70:70 /your/path/pgdata Puis dans docker-compose.yml :
# Remplacer :
- pgdata:/var/lib/postgresql/data
# Par :
- /your/path/pgdata:/var/lib/postgresql/data Retirez pgdata de la section volumes: en bas du fichier s’il ne sert plus.
Attention
Ne copiez pas le dossier PostgreSQL tant que le conteneur tourne : vous obtiendriez une copie incohérente. Sauvegarde à chaud : pg_dump. Sinon arrêtez d’abord avec docker compose stop.