Skip to Content

Self-Host Nextcloud: Your Own Private Google Drive in 20 Minutes

Deploy your own private cloud storage with Docker Compose — complete step-by-step guide

Self-Host Nextcloud: Your Own Private Google Drive in 20 Minutes

Tired of Google scanning your files? Here's how to build a private, self-hosted cloud storage platform that you fully control — with zero vendor lock-in.

The Problem with Big Tech Cloud Storage

Google Drive, Dropbox, and OneDrive are convenient — until they're not. Privacy concerns, storage limits, sudden account bans, and subscription creep are real problems. If you're running a business or just value your digital sovereignty, relying on third-party clouds for sensitive data is a liability.

Nextcloud is the open-source answer. It's a self-hosted file sync and share platform that gives you:

  • Full data ownership — your files stay on your server
  • No storage limits — constrained only by your disk size
  • End-to-end encryption options for sensitive data
  • Collaboration tools — document editing, calendars, contacts, chat
  • Zero subscription fees — completely free and open source

In this guide, you'll deploy Nextcloud with Docker Compose in about 20 minutes. Let's go.

Prerequisites

  • A VPS or dedicated server (recommended: 2+ vCPU, 4GB RAM, 20GB+ storage)
  • Docker and Docker Compose installed
  • A domain pointed at your server (optional but recommended for HTTPS)
  • Basic familiarity with Linux CLI

Step 1: Create the Project Directory

mkdir -p ~/nextcloud && cd ~/nextcloud

Step 2: Docker Compose Configuration

Create a docker-compose.yml file:

version: '3.8'

services:
  db:
    image: mariadb:10.6
    container_name: nextcloud_db
    restart: always
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    volumes:
      - db_data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=your_root_password_here
      - MYSQL_PASSWORD=your_db_password_here
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    networks:
      - nextcloud_network

  redis:
    image: redis:alpine
    container_name: nextcloud_redis
    restart: always
    networks:
      - nextcloud_network

  app:
    image: nextcloud:latest
    container_name: nextcloud_app
    restart: always
    ports:
      - 8080:80
    links:
      - db
      - redis
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      - MYSQL_PASSWORD=your_db_password_here
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - REDIS_HOST=redis
    depends_on:
      - db
      - redis
    networks:
      - nextcloud_network

  cron:
    image: nextcloud:latest
    container_name: nextcloud_cron
    restart: always
    volumes:
      - nextcloud_data:/var/www/html
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis
    networks:
      - nextcloud_network

volumes:
  db_data:
  nextcloud_data:

networks:
  nextcloud_network:
    driver: bridge

Security note: Replace your_root_password_here and your_db_password_here with strong, unique passwords.

Step 3: Deploy the Stack

docker compose up -d

Docker will pull the images and start all containers. This takes 2-3 minutes depending on your connection.

Step 4: Complete the Web Setup

Open your browser and navigate to:

http://YOUR_SERVER_IP:8080

You'll see the Nextcloud setup wizard. Create an admin account and configure the database:

  • Database user: nextcloud
  • Database password: (the one you set in docker-compose.yml)
  • Database name: nextcloud
  • Database host: db

Click Finish setup and wait 30-60 seconds for initialization.

Step 5: Enable Redis for File Locking (Performance Boost)

After setup, enable Redis by adding this to your Nextcloud config:

docker exec -u www-data nextcloud_app php occ config:system:set redis host --value=redis
docker exec -u www-data nextcloud_app php occ config:system:set redis port --value=6379
docker exec -u www-data nextcloud_app php occ config:system:set memcache.locking --value=\OC\Memcache\Redis
docker exec -u www-data nextcloud_app php occ config:system:set memcache.local --value=\OC\Memcache\Redis

Step 6: Add HTTPS with Traefik (Optional but Recommended)

For production, use Traefik as a reverse proxy with automatic SSL:

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.nextcloud.rule=Host(`cloud.yourdomain.com`)"
  - "traefik.http.routers.nextcloud.tls.certresolver=letsencrypt"
  - "traefik.http.services.nextcloud.loadbalancer.server.port=80"

Remove the ports: section and add this to the app service in your docker-compose.yml.

Verification Steps

  1. Check container status: docker compose ps — all services should show "Up"
  2. Test file upload: Drag a file into the Nextcloud web UI
  3. Verify database connection: docker logs nextcloud_db — look for "ready for connections"
  4. Check Redis: docker exec nextcloud_redis redis-cli ping — should return PONG

Next Steps & Related Guides

  • 🔒 Enable 2FA in Nextcloud security settings
  • 📱 Install mobile apps for iOS/Android auto-sync
  • 🗂️ Add OnlyOffice or Collabora for document editing
  • 💾 Configure automated backups with Borgmatic or Restic
  • 🚀 Scale up with S3-compatible object storage (MinIO) for external storage

Want to go deeper? Check out our guides on Traefik reverse proxy setup and automated backup strategies.


Self-hosting isn't just about saving money — it's about owning your data. Nextcloud gives you the tools to do exactly that, without sacrificing usability.

Questions or stuck on a step? Drop a comment below.

Self-Host n8n: Workflow Automation in 15 Minutes
Deploy the most powerful open-source workflow automation platform with Docker — no per-task pricing, full data control