Self-host Nextcloud behind CGNAT with Docker (tested over http only)
Nextcloud is a file-sharing and sync server you can run at home. If your internet provider shares one address between many customers (CGNAT), or your router will not forward ports, nobody outside can reach it. This page runs Nextcloud in Docker Compose and reaches it from the internet through a TunnelNet address.
Use https before you put real files on it
We tested this over plain http on a test machine. On http, your password and your files cross the internet unencrypted. We did not test https. Before real files, point a domain at the address and put a reverse proxy with a certificate in front. The Caddy front door in A public IP for a Docker host behind CGNAT is the pattern, but we have not run it with Nextcloud.
Tested on
Date: 18 November 2026 · Host: Debian 12, Docker Engine 29.10.0 and Docker Compose v5.8.0, a test virtual machine with 2 CPUs and 2 GB of memory in our lab, behind a NAT router with no port forwarding. This is not carrier CGNAT, but inbound behaves the same. · Images: nextcloud:31-apache (Nextcloud 31.0.14) and mariadb:11.4 · On the real service: the normal TunnelNet installer, on an internal test account · The visitor: a test machine in Atlanta.
Not tested: https, a domain and certificates, Nextcloud's own security scan (it needs https), phone and desktop sync apps (we used WebDAV with curl), carrier CGNAT itself, backups, Nextcloud AIO (a different install method), speed and large uploads. The address 203.0.113.47 is a documentation example.
Before you start
You need a Docker host with TunnelNet installed, so it has its own public address and nothing is open yet. The install is shown in Expose a Docker container without port forwarding.
1. Put the passwords in files
Passwords go in files, not in the compose file:
$ sudo mkdir -p /srv/nextcloud && cd /srv/nextcloud
$ sudo sh -c 'umask 077; head -c 18 /dev/urandom | base64 > db.txt; head -c 18 /dev/urandom | base64 > admin.txt'
admin.txt is the Nextcloud admin password you log in with.
Undo: delete the two files.
2. The compose file
This is the compose.yaml we ran:
services:
db:
image: mariadb:11.4
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED
environment:
MARIADB_DATABASE: nextcloud
MARIADB_USER: nextcloud
MARIADB_PASSWORD_FILE: /run/secrets/db
MARIADB_RANDOM_ROOT_PASSWORD: "1"
secrets: [db]
volumes:
- db:/var/lib/mysql
app:
image: nextcloud:31-apache
restart: unless-stopped
ports:
- "8090:80"
environment:
MYSQL_HOST: db
MYSQL_DATABASE: nextcloud
MYSQL_USER: nextcloud
MYSQL_PASSWORD_FILE: /run/secrets/db
NEXTCLOUD_ADMIN_USER: admin
NEXTCLOUD_ADMIN_PASSWORD_FILE: /run/secrets/admin
NEXTCLOUD_TRUSTED_DOMAINS: "localhost 203.0.113.47"
secrets: [db, admin]
volumes:
- html:/var/www/html
depends_on: [db]
secrets:
db:
file: ./db.txt
admin:
file: ./admin.txt
volumes:
db:
html:
Put your TunnelNet address (or your domain) in NEXTCLOUD_TRUSTED_DOMAINS. Nextcloud reads it only on the first start. Phones and desktop apps need to use the same name you put there.
3. Start it and wait for the first install
$ sudo docker compose up -d
Container nextcloud-db-1 Started
Container nextcloud-app-1 Started
$ curl -s http://127.0.0.1:8090/status.php
{"installed":true,"maintenance":false,"needsDbUpgrade":false,"version":"31.0.14.1","versionstring":"31.0.14",...}
The first install took about 2.5 minutes (154 seconds) on this small virtual machine. Until then the page is not ready. Memory in use with both containers running: about 570 MB.
Undo: sudo docker compose stop stops Nextcloud. sudo docker compose down -v also deletes your files and database, so use it only to start over.
4. Open it to the internet
$ sudo tnet ports allow tcp 8090 --note=nextcloud
Allowed tcp 8090
From the outside machine:
03:14:13 visitor -> 203.0.113.47:8090/status.php: {"installed":true,...,"versionstring":"31.0.14",...} (24 s after allow)
03:14:13 login page: http 200
upload a file (WebDAV PUT): http 201
download it back: file from Atlanta
same address, a name not in trusted domains: http 400
The last line is Nextcloud's own protection: it refuses names you did not list in trusted domains.
Undo:
$ sudo tnet ports deny 8090
Denied port 8090
It stopped answering 55 seconds later.
Limits
- Outgoing mail on port 25 is blocked, so Nextcloud's email notifications need a mail provider on port 587 or 465. We did not test that.
- Nextcloud sees visitors as coming from TunnelNet, not from their own address: in our run, every outside request in its log showed one internal TunnelNet address. This matters for its login-attempt limits.
- 1 TB a month is included, then 10 Mbit/s until the 1st of the month (an extra 1 TB costs $15).