All guides
Containers · 12 min · Intermediate

Connect a Custom Domain to a Container

Point your own domain at a container's exposed port, with optional HTTPS via a reverse proxy.

Every container gets two exposed ports: an SSH port (22 inside) and an extra port (80 inside). The extra port is what you point a custom domain at — typically your web server. This guide walks through pointing example.com at a container running an HTTP service.

What you need

  • A running container — note its IP and "Extra Port" from the detail page.
  • A web server inside it listening on port 80 (Nginx, Caddy, an Express app, anything).
  • A domain you control with DNS access.

Step 1 — Run a web server inside the container

Quick smoke test with Nginx:

bash
apt update && apt install -y nginx
echo "<h1>hello from $(hostname)</h1>" > /var/www/html/index.html
systemctl enable --now nginx

Confirm it responds from your laptop using the container's host and extra port:

bash
curl http://<CONTAINER_HOST>:<EXTRA_PORT>/

Step 2 — Point DNS at the container

In your DNS provider, create an A record for the subdomain (or apex) you want, pointing at the container's IP. Because the container does not listen on port 80 of the host (it listens on the extra port), bare DNS isn't enough — browsers will hit port 80 of the host, where nothing answers.

You have two choices:

Option A — Use a reverse proxy (recommended)

Run a proxy in front of your container that listens on 80/443 and forwards to your container's extra port. Cloudflare with a free Origin rule is the easiest:

  1. Add the domain to Cloudflare (free plan is fine).
  2. Create an A record pointing at the container's IP, proxied (orange cloud on).
  3. Go to Rules → Origin Rules → Create rule. Match Hostname = your subdomain. Override Destination Port to your extra port.
  4. Cloudflare automatically issues HTTPS for the domain — no work in the container.

Option B — Use a service like duckdns or a dedicated reverse proxy you run

If you want to skip Cloudflare, run Caddy on a small box (or another SparkCloud container) that listens on 80/443 and proxies to your real container. Caddy auto-issues Let's Encrypt certs:

caddy
example.com {
  reverse_proxy <CONTAINER_HOST>:<EXTRA_PORT>
}

Step 3 — Verify

bash
curl -I https://example.com
# should return 200 OK from your nginx