Expose a Docker container without port forwarding (tested)
A container works on your own network but nobody outside can reach it. You cannot add a port forward on your router, or your internet provider shares one address between many customers (CGNAT, common on Starlink, 5G and some fibre lines). This page shows how to give the Docker host its own public address and open only the ports you choose.
Tested on
Date: 18 November 2026 · Docker host: Debian 12 (kernel 6.1), a small test virtual machine in our lab, with Docker Engine 29.10.0 and Docker Compose v5.8.0 from Docker's own apt repository · Its internet: a normal home-style line behind a NAT router with no port forwarding. This is not carrier CGNAT, but the effect on inbound connections is the same: nothing from outside gets in.
On the real service: the normal TunnelNet installer on an internal test account. The visitor: a separate test machine in Atlanta, on the internet.
Not tested: carrier CGNAT itself, https and certificates, UDP ports, Docker on Windows or Mac, ufw, and the -p 127.0.0.1:... variant. Addresses here are documentation examples: 203.0.113.47 is your TunnelNet address and 198.51.100.77 your home line's own address.
0. Docker
We installed Docker from Docker's own repository on Debian 12. If you already have Docker, skip this step.
$ sudo apt-get install -y ca-certificates curl
$ sudo install -m 0755 -d /etc/apt/keyrings
$ sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list
$ sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
$ docker --version
Docker version 29.10.0, build fdd4b8e
$ docker compose version
Docker Compose version v5.8.0
1. Run a container the usual way
$ echo "hello from a container" | sudo tee /srv/web/index.html
$ sudo docker run -d --name web --restart unless-stopped -p 8080:80 -v /srv/web:/usr/share/nginx/html:ro nginx:1.27-alpine
$ docker ps --format "{{.Names}} {{.Image}} {{.Ports}}"
web nginx:1.27-alpine 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp
$ curl -s http://127.0.0.1:8080/
hello from a container
Undo: docker rm -f web.
2. The problem: from outside, it does not answer
From a machine on another network, to the home line's own address:
$ curl -s -m8 -o /dev/null -w "http %{http_code}\n" http://198.51.100.77:8080/
http 000 (curl exit 28: timed out after 8 s)
With no port forward on the router, nothing gets in. Behind CGNAT you cannot add a port forward at all, because the router's outside address is not yours. Not sure which case you are in? See Am I behind CGNAT?.
3. Install TunnelNet on the Docker host
Run the command from your TunnelNet dashboard on the host:
$ curl -fsSL https://tunnelnet.io/install.sh | sudo bash -s -- <your code>
...
[ OK ] handshake
Enrolled!
Public IP: 203.0.113.47
In our run this took a few minutes (277 seconds). A [ ?? ] public-ip — could not tell line is normal on a brand-new address and clears by itself.
4. Check what is open
New machines start with nothing reachable from the internet:
$ sudo tnet ports
Mode: filtered
(no rules)
From the outside machine, ports 8080, 8081 and 22 on 203.0.113.47 all gave no answer.
Trust tnet ports
In our run the installer's summary said inbound traffic to the public address was open, but tnet ports said filtered and our outside test confirmed that nothing answered. Trust tnet ports, and check it after the install. We reported the wording to the people who maintain the installer.
5. Open the container's port
$ sudo tnet ports allow tcp 8080 --note=web-container
Allowed tcp 8080
$ sudo tnet ports
Mode: filtered
tcp 8080 web-container
From the outside machine:
02:59:02 visitor -> 203.0.113.47:8080: hello from a container (9 s after allow)
02:59:02 visitor -> 203.0.113.47:8081 (not opened): (no answer)
You open the port Docker published on the host (-p 8080:80 means 8080), not the container's own port 80. No router change and no Docker change are needed.
Undo: step 6.
6. Close it again
$ sudo tnet ports deny 8080
Denied port 8080
$ sudo tnet ports
Mode: filtered
(no rules)
From outside, it stopped answering 35 seconds after the deny.
A mistake we made: deny takes only the port. tnet ports deny tcp 8080 fails with ERROR: 'tcp' is not a port., and the port stayed open until we ran the command correctly. After closing a port, run sudo tnet ports and check.
Good to know
- Docker publishes ports on every address of the host, including the TunnelNet one (
0.0.0.0:8080above). Docker's own documentation says published ports also skipufwrules; we did not testufwin this run. What we did test: on TunnelNet, a port is reachable from the internet only aftertnet ports allow. Port 8081 was never allowed and never answered. tnet ports allowopens the port to everyone. There is no "only from this address" option in the command. Close ports you are not using.- Outgoing traffic: on the $10 plan, the host's and containers' own browsing still leaves through your home line. Only incoming connections use the TunnelNet address.
Limits
- 1 TB a month included, then 10 Mbit/s until the 1st of the month (an extra 1 TB costs $15).
- Outgoing mail on port 25 is blocked.
- Your containers see visitors as coming from TunnelNet, not from the visitor's own address.
Running Docker inside a Proxmox VM? Docker on Proxmox: VM or LXC? covers that choice.