r/devops • u/neuralbeans • Sep 09 '26
Discussion Best practices for exposing multiple websites in Docker containers on the same Ubuntu server to the web
I have an Ubuntu web server that I'd like to contain multiple websites on. Each website should have its own isolated environment in a Docker container (open to suggestions if Docker is not ideal).
I'm thinking that the public URLs should be like
- example.com/website1
- example.com/website2
- etc
What's the best way to make this connection between the public URL and the Docker container (also open to suggestions for better ways to expose the containers)?
Another question: Would the logs of each website be inside the container or are they supposed to be outside for easy review?
17
Upvotes
39
u/CertainAd3152 Sep 09 '26
Have an nginx or any other proxy and proxy traffic via website name. Inter service docker container communication is fairly good for this use case
9
u/Party_Artist2978 Sep 09 '26
I'm definitely not super experienced with this, but I have the following setup:
Caddy to handle the routing, so I have a Caddyfile to re-direct to subdomains, and docker-compose files for each website or app, with each app using its own network that Caddy is aware of, so none of the websites are exposed to the internet directly, but only via Caddy.
I did run into this issue if you want to set up subfolders instead of subdomains: https://caddy.community/t/the-subfolder-problem-or-why-cant-i-reverse-proxy-my-app-into-a-subfolder/8575
I'd be keen to hear from others though!
7
u/ForkMeJ Sep 09 '26
If these are separate sites, I'd use subdomains instead of path prefixes. website1.example.com and website2.example.com are usually much simpler than /website1 and /website2 because a lot of apps assume they own /. Put Nginx, Caddy, or Traefik on the host as the reverse proxy, terminate TLS there, and route by Host header to each container over an internal Docker network. For logs, I wouldn't rely on shelling into containers. Have the apps write to stdout/stderr and collect that with Docker's logging driver or something lightweight like Loki/Promtail so each app stays isolated but the logs are still easy to review in one place. If you end up needing tighter ownership controls, secrets, RBAC, or separate dev/prod environments for internal apps, I work on the open-source tool Compartment, and that's one place it can help without jumping straight to Kubernetes.
3
u/Angelsomething Sep 09 '26
Reverse proxy is what you seek. Caddy is a good one and it's all déclarative yaml.
2
u/Stunning_Tea9670 Sep 09 '26
Expose docker containers to only nginx on same network, config using docker names, or run a simple cloudflare tunnel to expose the service over the internet
2
u/raisputin Sep 09 '26
Why not just use Apache virtual hosts, or do they truly require full isolation?
3
u/InconsiderableArse Sep 09 '26
You could use Docker swarm, or even a k3s in your server.
everything that needs to persist needs to be outside of the container. database in a different service, code in a versioning system, files in a volume, logs in a centralised logging system
3
u/Fresh_Sock8660 Sep 09 '26
I would go the subdomain route and use caddy. Logs should be in a mounted volume, make sure it has a lifecycle and isn't just blindly accumulating.
1
u/ByronEster Sep 09 '26
I do this with nginx-proxy-manager NPM.
It is simple, easy to use, robust and handles SSL cert generation and rotation
1
u/CyberKiller40 DevOps Ninja Sep 09 '26
Run it in swarm mode, use traefik to route the incoming requests.
1
u/b1urbro Sep 09 '26
Best practice? Don't expose it at all if you don't know what you're doing. Use something like Cloudflare tunnels + Cloudflare Zero trust for auth. It's very simple to set up and secure out of the box.
Quick overview of how that would look like:
- Spin a cloudflared container with your token
- Run the containers on the same docker network
- Route the containers via Cloudflare tunnels, you point DNS X (eg asd.dsa.com) to Container Y (eg 192.168.0.100:3000). Repeat for multiple containers. Done.
- Add Zero Trust access gate if you're not absolutely sure about your/your apps auth process
1
u/STLWaffles Sep 09 '26
Use a reverse proxy to expose them. You can either do it path based or domain/subdomain (depending on your DNS setup).
1
u/gunsofbrixton Sep 09 '26
Traefik has been pretty good for this.
1
u/neveralone59 Sep 10 '26
+1 for cloudflare zero trust, but recommend using a reverse proxy as it gives you things like high availability
1
u/whatisuser Sep 10 '26
Look up traefik
1
u/DarkChemical_DC Sep 14 '26
Im using HAProxy, but most of the reverse proxies can do this.
1
u/Toesismyhobby Sep 16 '26
Traefik shines in this situation. Caddy is good. But traefiks integration to docker is insanely smooth.