version: "3.8"

services:
  jellyfin:
    image: jellyfin/jellyfin:latest
    container_name: jellyfin
    restart: unless-stopped
    networks:
      - jellyfin-network
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
      - HEALTHCHECK_URL=http://localhost:8096/health
      - JELLYFIN_DATA_DIR=/config
      - JELLYFIN_CACHE_DIR=/cache
      - JELLYFIN_CONFIG_DIR=/config/config
      - JELLYFIN_LOG_DIR=/config/log
      - JELLYFIN_WEB_DIR=/jellyfin/jellyfin-web
      - JELLYFIN_FFMPEG=/usr/lib/jellyfin-ffmpeg/ffmpeg
      - XDG_CACHE_HOME=/cache
      - MALLOC_TRIM_THRESHOLD_=131072
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
    volumes:
      - /opt/jellyfin/config:/config
      - /opt/jellyfin/cache:/cache
      - /mnt/pi-media/movies:/media/movies
      - /mnt/pi-media/tv_shows:/media/tv_shows
    devices:
      - /dev/dri:/dev/dri
    healthcheck:
      test: ["CMD-SHELL", "curl --noproxy 'localhost' -Lk -fsS \"$${HEALTHCHECK_URL}\" || exit 1"]
      interval: 30s
      timeout: 30s
      retries: 3
      start_period: 10s
    ports:
      - "8096:8096"

networks:
  jellyfin-network:
    driver: bridge