# Nextcloud-Stack
services:
  nextcloud:
    image: nextcloud:31.0-fpm 
    container_name: nextcloud
    depends_on:
      - nextcloud-redis
    environment:
      - DOMAIN=${DOMAIN}
      - NEXTCLOUD_ADMIN_USER=${NEXTCLOUD_ADMIN_USER:-admin}
      - NEXTCLOUD_ADMIN_PASSWORD=${NEXTCLOUD_ADMIN_PASSWORD:-admin}
      - NEXTCLOUD_DEFAULT_PHONE_REGION=DE
      - ONLYOFFICE_JWT_SECRET=${ONLYOFFICE_JWT_SECRET}
      - POSTGRES_DB=${NEXTCLOUD_DB_NAME}
      - POSTGRES_HOST=${NEXTCLOUD_DB_HOST}
      - POSTGRES_PASSWORD=${NEXTCLOUD_DB_PASSWORD}
      - POSTGRES_USER=${NEXTCLOUD_DB_USER}
      - OVERWRITEPROTOCOL=https
      - OVERWRITEHOST=${NEXTCLOUD_DOMAIN}
      - REDIS_HOST=nextcloud-redis
    labels:
      - "traefik.enable=false"
    volumes:
      - nextcloud-data:/var/www/html
      - ./hooks/post-installation:/docker-entrypoint-hooks.d/post-installation
    expose:
      - 80
      - 9000
    networks:
      - nextcloud
      - traefik
      - onlyoffice
      - database
    restart: unless-stopped

  nextcloud-reverse-proxy:
    container_name: nextcloud-reverse-proxy
    image: nginx:1.27
    depends_on:
      - nextcloud
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.nextcloud-reverse-proxy.rule=Host(`${NEXTCLOUD_DOMAIN}`)"
      - "traefik.http.routers.nextcloud-reverse-proxy.entrypoints=web,websecure"
      - "traefik.http.routers.nextcloud-reverse-proxy.middlewares=https-redirect"
      - "traefik.http.routers.nextcloud-reverse-proxy.tls=true"
      - "traefik.http.routers.nextcloud-reverse-proxy.tls.certresolver=le"
      - "traefik.http.services.nextcloud-reverse-proxy.loadbalancer.server.port=80"
    volumes:
      - ./reverse-proxy/nginx.conf:/etc/nginx/nginx.conf
      - nextcloud-data:/var/www/html
    networks:
      - nextcloud
      - traefik
      - onlyoffice
    restart: unless-stopped

  nextcloud-redis:
    image: redis:alpine
    container_name: nextcloud-redis
    networks:
      - nextcloud
    restart: unless-stopped

volumes:
  nextcloud-data:
    name: nextcloud-data

networks:
  database:
    external: true
  nextcloud:
    name: nextcloud
    external: true
  traefik:
    external: true
  onlyoffice:
    external: true
