This guide walks you through installing Nextcloud with Docker on macOS and exposing it publicly via Cloudflare Tunnel, ideal for dynamic IP setups where port forwarding is not possible. This setup ensures that Nextcloud runs automatically on reboot and is securely accessible over the internet.
- A macOS device (laptop, Mac mini, etc.)
- Docker and Docker Compose installed
- A registered domain in Cloudflare
- Homebrew and
cloudflaredinstalled - Basic terminal usage knowledge
- Go to https://cloudflare.com
- Create an account and add your domain (e.g.,
yourdomain.com) - Point your DNS to Cloudflare's nameservers (Cloudflare will guide you)
- Once verified, go to DNS settings and create a record like:
Type: CNAME
Name: nextcloud
Target: `@` (or your main domain)
Proxy status: Proxied (orange cloud)
Make sure cloudflared is installed:
brew install cloudflaredThen log in and authorize your domain:
cloudflared tunnel loginA browser window will open asking you to authenticate with Cloudflare.
Create a shell script with the full setup process:
nano ~/setup_nextcloud_tunnel.shPaste the script provided earlier (including tunnel ID fix). Save and run:
chmod +x ~/setup_nextcloud_tunnel.sh
./setup_nextcloud_tunnel.shThe script will:
- Create a Docker Compose file for Nextcloud
- Spin up Nextcloud and MariaDB containers
- Create a Cloudflare Tunnel and configure
config.yml - Link the tunnel to your subdomain
nextcloud.yourdomain.com - Launch the tunnel
Open:
https://nextcloud.yourdomain.com
On the first load:
- Set an admin username and password
- Under Database, use:
- Type:
MySQL/MariaDB - User:
nextcloud - Password:
nextcloud - Database name:
nextcloud - Host:
db
- Type:
Click Install.
Create a file ~/start_nextcloud.sh:
#!/bin/bash
export PATH="/opt/homebrew/bin:$PATH"
cd /Users/$(whoami)/nextcloud
docker-compose up -dMake it executable:
chmod +x ~/start_nextcloud.shCreate a launchd agent:
mkdir -p ~/Library/LaunchAgents
nano ~/Library/LaunchAgents/com.user.nextcloud.plistPaste:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.nextcloud</string>
<key>ProgramArguments</key>
<array>
<string>/Users/$(whoami)/start_nextcloud.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
</dict>
</plist>Load the service:
launchctl load ~/Library/LaunchAgents/com.user.nextcloud.plistCloudflare has built-in support:
cloudflared service installIt will automatically run the tunnel on system boot using the config.yml.
You now have:
- A Nextcloud instance running on macOS
- Publicly available at
https://nextcloud.yourdomain.com - No open ports required
- Automatically restarted after reboot