A performance-optimized Nextcloud deployment using Docker Compose. This stack includes a PostgreSQL database, Redis for memory caching, and a dedicated cron container for background tasks. It is pre-configured for use with a Traefik reverse proxy, also running in Docker.
- Database: PostgreSQL 16 (Alpine-based)
- Caching: Redis for improved file locking and performance
- Background jobs: Dedicated cron container for reliable system maintenance
- Security: Pre-configured Traefik labels for HSTS and .well-known DAV redirects
- Utilities: Custom scripts for log management and database backups
Before starting, ensure you have:
- Docker
- An existing Docker network named proxy-net (used by Traefik)
- Traefik running in Docker - use my trafik-docker repo, which is made for this
- A .env file in the root directory
The included .env file needs to be edited for your instance of Nextcloud.
BASENAME=nextcloud
POSTGRES_USER=nextcloud
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=nextcloud
DOMAIN=cloud.yourdomain.com
NEXTCLOUD_DATA=./nextcloud_data
RESOLVER=acmeweb # Default in my Traefik containerIt should be running on the same network as Nextcloud is configured to.
cp -r nextcloud-docker /home/docker
cd /home/docker/nextcloud-docker
rm -rf .git .githubEnsure your DNS records (A/AAAA) are pointing to your server, then run:
docker compose up -d- Navigate to your ${DOMAIN} in a browser
- Create your admin Account
- Since the database variables are passed via the environment, Nextcloud should detect the PostgreSQL setup automatically
chmod +x post-setup clearlog dumpdb restoredbOnce the admin user is created and you can log in, run the included post-setup script to enable Redis, internal cron, and apply various system fixes:
./post-setupThis repository includes several utility scripts to simplify management:
| Script | Description |
|---|---|
| ./clearlog | Clears the nextcloud.log from the main container to save space |
| ./dumpdb | Dumps the Postgres database into the ./backups directory. Run this before upgrades! |
| ./restoredb | Restores a database dump from the ./backups directory |
| ./post-setup | Configures Redis, cron, and performance tweaks after initial install |
Before performing major upgrades (e.g., changing the Nextcloud image version), always run a database dump:
./dumpdbThe backup will be stored in the ./backups folder. To restore, ensure the containers are running and execute ./restoredb.
- PHP Memory Limit: Set to 2G to support the Nextcloud Office suite
- Upload limit: Set to 10G. Note that you may also need to adjust your Traefik/Nginx proxy "max body size" to match
- Log rotation: All containers are limited to 3 files of 10MB each to prevent disk exhaustion