Nextcloud SetupΒΆ
Self-hosted productivity platform with file sync & share, calendars, contacts and more.
π οΈ Service ConfigurationΒΆ
- This setup uses the shared Docker Compose anchors for
- Logging (
default-logging
) - Labels (
default-labels
) - Resource limits (
resource-limits
)
Core ServicesΒΆ
nextcloud-postgres:
image: postgres:latest
container_name: nextcloud-postgres
hostname: nextcloud-postgres
restart: always
<<: *resource-limits
logging:
<<: *default-logging
options:
<<: *default-logging-options
loki-external-labels: job=nextcloud-postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
environment:
POSTGRES_USER: ${POSTGRES_USER:-nextcloud} # (1)
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} # (2)
POSTGRES_DB: ${POSTGRES_DB:-nextcloud} # (3)
UID: ${UID_NAS_ADMIN:-1026} # optional (4)
GID: ${GID_NAS_ADMIN:-100} # optional (5)
volumes:
- type: bind
source: /etc/localtime
target: /etc/localtime
read_only: true
- type: bind
source: ${MOUNT_PATH_DOCKER_ROOT:?path required}/nextcloud/db
target: /var/lib/postgresql/data
labels:
<<: *default-labels
monitoring: nextcloud-postgress
networks:
dockerization:
- β Database username (default:
nextcloud
) - β Database password (default:
nextcloud
) - β Database name (default:
nextcloud
) - β Optional user ID for volume permissions (default: 1026)
- β Optional group ID for volume permissions (default: 100)
nextcloud-redis:
image: redis:alpine
container_name: nextcloud-redis
hostname: nextcloud-redis
restart: always
<<: *resource-limits
logging:
<<: *default-logging
options:
<<: *default-logging-options
loki-external-labels: job=nextcloud-redis
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
dockerization:
environment:
UID: ${UID_NAS_ADMIN:-1026} # optional (1)
GID: ${GID_NAS_ADMIN:-100} # optional (2)
volumes:
- type: bind
source: /etc/localtime
target: /etc/localtime
read_only: true
labels:
<<: *default-labels
monitoring: nextcloud-redis
- β Optional user ID for volume permissions (default: 1026)
- β Optional group ID for volume permissions (default: 100)
nextcloud:
image: nextcloud:latest
container_name: nextcloud
hostname: nextcloud
restart: always
<<: *resource-limits
logging:
<<: *default-logging
options:
<<: *default-logging-options
loki-external-labels: job=nextcloud
healthcheck:
test: ["CMD-SHELL", "curl --fail http://localhost:80 || exit 1"]
interval: 60s
retries: 5
start_period: 20s
timeout: 10s
ports:
- "${NEXT_CLOUD_PORT:-81}:80"
volumes:
- type: bind
source: /etc/localtime
target: /etc/localtime
read_only: true
- type: bind
source: ${MOUNT_PATH_DOCKER_ROOT}/nextcloud/app
target: /var/www/html
environment:
POSTGRES_USER: ${POSTGRES_USER:-nextcloud} # (1)
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nextcloud} # (2)
POSTGRES_DB: ${POSTGRES_DB:-nextcloud} # (3)
POSTGRES_HOST: ${POSTGRES_HOST:-nextcloud-postgres} # (4)
NEXTCLOUD_DATADIR: /mnt/ncdata # (5)
NEXTCLOUD_UPLOAD_LIMIT: 10G # (6)
NEXTCLOUD_MEMORY_LIMIT: 512M # (7)
TRUSTED_DOMAINS: nextcloud.${SYNOLOGY_BASIC_URL:?Synology URL required} # (8)
SMTP_HOST: ${SMTP_HOST:-smtp.mail.me.com} # (9)
SMTP_SECURE_MODE: tls # (10)
SMTP_PORT: ${SMTP_PORT:-587} # (11)
SMTP_NAME: ${EMAIL} # (12)
SMTP_PASSWORD: ${SMTP_PASSWORD} # (13)
UID: ${UID_NAS_ADMIN:-1026} # optional (14)
GID: ${GID_NAS_ADMIN:-100} # optional (15)
depends_on:
nextcloud-postgres:
condition: service_healthy
nextcloud-redis:
condition: service_healthy
labels:
<<: *default-labels
monitoring: nextcloud
networks:
dockerization:
- β PostgreSQL username (matches database service)
- β PostgreSQL password (matches database service)
- β Database name (matches database service)
- β Database hostname (using Docker service name)
- β Data storage path inside container
- β Max upload size (10GB)
- β PHP memory limit (512MB)
- β Trusted domain (required)
- β SMTP server for email
- β SMTP encryption (TLS)
- β SMTP port (587)
- β Email address for SMTP auth
- β SMTP password (must be set in
.env
) - β User ID for volume permissions (default: 1026)
- β Group ID for volume permissions (default: 100)
π Required Environment VariablesΒΆ
Refer to Environment Variables documentation for:
Variable | Description | Required |
---|---|---|
MOUNT_PATH_DOCKER_ROOT |
Storage path | β |
SYNOLOGY_BASIC_URL |
Domain for trusted hosts | β |
EMAIL |
Admin email for SMTP | β |
SMTP_PASSWORD |
SMTP auth password | β |
UID_NAS_ADMIN |
User ID for volume permissions | β οΈ Recommended |
GID_NAS_ADMIN |
Group ID for volume permissions | β οΈ Recommended |
Security Notice
- Be stored in
.env
files - Have restricted permissions (
chmod 600
) - Never be committed to version control
- Be rotated periodically
π DeploymentΒΆ
- Create
.env
file with required variables - Initialize volumes
- Start services
- Access web UI at
http://yourdomain.com:81
π MaintenanceΒΆ
- Backups
- Regularly backup both the PostgreSQL and app volumes
- Updates
- Logs