Install Nextcloud with Docker: Step-by-Step Guide
In this article
This guide walks you through installing Nextcloud, a self-hosted file sync and sharing platform, using Docker. You’ll end up with a working Nextcloud instance accessible via your browser, with data stored in persistent volumes so nothing is lost when containers restart. Before starting, you need a Linux server (or any machine with Docker), a domain name or IP address, and basic comfort with the command line.
What You'll Need
- A server or computer running Linux (Ubuntu/Debian recommended) with at least 2 GB RAM and 10 GB free disk space.
- Docker and Docker Compose installed. If not installed, see the official Docker docs for your OS.
- A domain name pointing to your server’s public IP (optional but recommended for HTTPS).
- Ports 80 and 443 open on your firewall if you plan to access Nextcloud from the internet.
- Basic command-line knowledge: navigating directories, editing files with nano or vim.
Step-by-Step
- Install Docker and Docker Compose (if not already present). On Ubuntu, run:
Verify withsudo apt update sudo apt install docker.io docker-compose-v2 sudo systemctl enable --now dockerdocker --versionanddocker compose version. - Create a project directory to keep things organized:
mkdir ~/nextcloud && cd ~/nextcloud - Create a
docker-compose.ymlfile using a text editor. Here’s a solid starting point:
Replace the passwords with strong, unique values.version: '3.8' services: db: image: mariadb:10.6 restart: always command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW volumes: - db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=change_me_root - MYSQL_PASSWORD=change_me_db - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud app: image: nextcloud:latest restart: always ports: - 8080:80 volumes: - nextcloud:/var/www/html environment: - MYSQL_HOST=db - MYSQL_PASSWORD=change_me_db - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud depends_on: - db volumes: db: nextcloud: - Start the containers in the background:
This downloads the images and starts MariaDB and Nextcloud. Wait a minute or two for the database to initialize.docker compose up -d - Complete the web installer. Open your browser and go to
http://YOUR_SERVER_IP:8080. You’ll see the Nextcloud setup page. Choose an admin username and password. For the database, select MySQL/MariaDB and enter:- Database user:
nextcloud - Database password: (the one you set for MYSQL_PASSWORD)
- Database name:
nextcloud - Database host:
db(the service name from the compose file)
- Database user:
- Verify persistence. Create a test file, then run
docker compose restartand confirm the file is still there. This ensures your volumes are working. - Set up HTTPS (recommended). For production, use a reverse proxy like Caddy or Nginx with Let’s Encrypt. For a quick local test, you can skip this, but for internet access, HTTPS is essential. A simple Caddy setup:
Run Caddy as another container and point your domain to the server.# Caddyfile nextcloud.example.com { reverse_proxy app:80 } - Configure trusted domains. If you access via IP or a domain, add it to
config/config.phpin the Nextcloud volume. Edit the file and add your domain to the'trusted_domains'array. Then restart the app container.
Common Mistakes
- Using weak or default passwords – always change them.
- Forgetting to open firewall ports – the web interface won’t be reachable.
- Using the wrong database host – it must be the service name (
db), notlocalhost. - Not persisting data – if you don’t use volumes, all data is lost when the container is removed.
- Exposing port 8080 directly to the internet without HTTPS – passwords are sent in plaintext.
- Editing files inside the container – changes vanish on container recreation. Always edit via the volume on the host.
Tips
- Use a dedicated user for Docker commands to avoid
sudoevery time. - Set up automatic backups of the
nextcloudanddbvolumes (e.g., withrsyncor a cron job). - Pin the Nextcloud image to a specific version (e.g.,
nextcloud:27.1) instead oflatestfor stability. - Increase PHP memory limit in the container if you have many apps or large files.
- Use a reverse proxy for HTTPS and to enable HTTP/2 for better performance.
- Monitor disk usage – Nextcloud stores file versions and trash, which can grow quickly.
Troubleshooting
- Web interface not loading: Check if containers are running:
docker compose ps. View logs:docker compose logs app. Ensure port 8080 is not blocked by a firewall. - Database connection error during install: Verify the database host is
db, and the credentials match the environment variables. Check the db logs:docker compose logs db. - “Trusted domain” error: Edit
nextcloud/config/config.phpand add your domain or IP to thetrusted_domainsarray, then restart the app container. - Permission issues: If you see “Can’t write into config directory”, run
docker compose exec app chown -R www-data:www-data /var/www/htmlfrom the project directory. - Container restarts repeatedly: Check the logs for the specific service. Often it’s a wrong password or a volume permission issue.
- Slow performance: Ensure your server meets the minimum RAM, and consider adding Redis for caching (advanced setup).
Frequently Asked Questions
Can I use SQLite instead of MariaDB?
Yes, for testing you can omit the db service and let Nextcloud use SQLite, but for production, MariaDB/PostgreSQL is recommended for performance and reliability.
How do I update Nextcloud?
Back up your volumes, then run docker compose pull and docker compose up -d. Nextcloud will run its upgrade routine on the next page load.
Where are my files stored?
In the Docker volume named nextcloud. You can find the actual path with docker volume inspect nextcloud – it’s typically under /var/lib/docker/volumes/ on the host.
Can I access Nextcloud via a subdirectory like /nextcloud?
Yes, but it requires extra configuration in the reverse proxy and in Nextcloud’s config. It’s easier to use a subdomain.
How do I enable HTTPS with Let’s Encrypt?
Use a reverse proxy like Caddy (which auto-renews certificates) or Nginx with certbot. Point your domain to the server and configure the proxy to forward to the app container.
What if I forget the admin password?
You can reset it from the command line: docker compose exec app php occ user:resetpassword admin. This works as long as the app container is running.