Tired of paying monthly for cloud storage? This guide walks you through setting up your own private cloud using Nextcloud on a Linux server with Docker Compose. You’ll learn how to deploy a self-hosted file sync and sharing service that gives you control over your data, privacy, and costs.
#!/usr/bin/env bash
set -e
# Install Docker & Docker Compose using the KeepItTechie install script
curl -fsSL https://wiki.kitpro.us/install-docker.sh | bash
# Create the Nextcloud project directory and navigate into it
mkdir -p ~/nextcloud
cd ~/nextcloud
# Create persistent data directories for Nextcloud and MariaDB
mkdir -p nextcloud db
# Create the Docker Compose file
nano docker-compose.yml
Paste the following Docker Compose YAML into docker-compose.yml:
services:
db:
image: mariadb:11
container_name: nextcloud-db
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ./db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: nextcloud
MYSQL_PASSWORD: nextcloud
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
app:
image: nextcloud:latest
container_name: nextcloud-app
restart: unless-stopped
ports:
- "8080:80"
links:
- db
volumes:
- ./nextcloud:/var/www/html
environment:
MYSQL_PASSWORD: nextcloud
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_HOST: db
Note: For this demo, the password
nextcloudis used for simplicity. In a real deployment, use strong, unique passwords and consider storing them in a.envfile instead of directly in the Compose file.
Start the containers in detached mode:
docker compose up -d
Check the status of running containers:
docker compose ps
View MariaDB logs to confirm database initialization:
docker logs nextcloud-db
Open your browser and navigate to:
http://SERVER-IP:8080
Replace SERVER-IP with your server’s IP address, for example:
http://192.168.1.50:8080
On the Nextcloud setup page, enter the database connection details:
nextcloudnextcloudnextclouddbImportant: Use
dbas the database host, notlocalhostor the server IP. This matches the Docker Compose service name and allows the app container to connect to the database container.
Cloud storage services like Google Drive, OneDrive, and Dropbox are convenient but come with ongoing costs and privacy tradeoffs. Building your own private cloud with Nextcloud lets you keep control of your data, avoid monthly fees, and learn valuable Linux and Docker skills.
db.nextcloud in production.| Problem | Cause | Fix |
|---|---|---|
| Nextcloud setup can’t connect to database | Incorrect database host or credentials | Use db as the database host; verify username/password in Compose environment vars. |
| Containers not starting | Docker or Compose not installed or errors | Check Docker service status; run docker compose logs for error details. |
| Data not persisting after restart | Volumes not mounted or wrong paths | Confirm ./db and ./nextcloud directories exist and are correctly mapped in Compose. |
| Cannot access Nextcloud in browser | Firewall or port not open | Ensure port 8080 is open and accessible on your server/network. |
This page was created alongside a KeepItTechie video.
Watch the full video: https://www.youtube.com/watch?v=AHWbFq_VfFQ
resources/stop-paying-for-cloud-storage-build-your-own-private-cloud/docker-compose.yml in the wiki content repository.