Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Self-Hosting a Dockerized App on WSL2, Exposed with a Cloudflare Tunnel

说明与用途

成功在 WSL2 内使用 Docker 部署 Node/Express + PostgreSQL 应用,并通过 Cloudflare 隧道公开真实域名,避免外部托管。

问题

Deploy a small Node/Express to-do app with Postgres persistence on Windows using WSL2, Docker Engine, and expose it via a real domain without paying for hosting.

结果

Successfully self-hosted a Dockerized Node/Express to-do app with Postgres inside WSL2 and exposed it at a real domain using a Cloudflare Tunnel, avoiding external hosting costs.

工作流

  • Install WSL2 Ubuntu via wsl --install -d Ubuntu and restart Windows
  • Create Unix user in Ubuntu
  • Install Docker Engine inside Ubuntu with curl -fsSL https://get.docker.com | sudo sh and add user to docker group
  • Log out/in to apply group membership
  • Set up project: copy .env.example to .env and edit DB credentials
  • Choose deployment path: either bare Dockerfile with host Postgres or docker-compose with Postgres container and crond sidecar
  • If using docker-compose, run sudo docker compose up --build -d
  • Verify app on localhost:3000 with curl -i http://localhost:3000
  • Install cloudflared Windows binary and login: cloudflared.exe tunnel login
  • Create tunnel: cloudflared.exe tunnel create todo-docker-poc
  • Route DNS: cloudflared.exe tunnel route dns todo-docker-poc todo-list-docker.gerardoleon.dev
  • Configure tunnel in cloudflared/config.yml with tunnel ID
  • Run tunnel from WSL2: cloudflared.exe tunnel --config "C:\%PROJECT%\todo-docker\cloudflared\config.yml" run todo-docker-poc
  • Access app via domain

证据

A proof-of-concept to-do app — Node/Express and Postgres, running in Docker on WSL2 — reachable at a real domain through a named cloudflared tunnel.

来源

If you already have WSL2 and a Cloudflare-managed domain, expect this to take a few minutes, not hours.

来源

  • 记录日期: 2026-09-21T11:15:41.266Z