What’s the best way to host multiple Dockerized websites on one Ubuntu server?

0
0
Asked By MellowPine47 On

I have an Ubuntu server and want to host several websites, with each site running in its own isolated Docker container. I'm considering URLs such as example.com/website1 and example.com/website2, but I'm open to using subdomains or another approach if that works better. What is the recommended way to route public web traffic to the correct container while keeping the application containers private? Also, should each site's logs remain inside its container, be stored in mounted volumes, or be collected through a centralized logging setup?

3 Answers

Answered By QuietLantern22 On

Caddy is a straightforward option: run it in its own Compose service, attach it to a shared proxy network, and put each website on that network without exposing its port on the host. Caddy can route by hostname and automatically obtain and renew certificates. Path-based routing can work, but applications often need special configuration for redirects, cookies, and asset URLs, so separate subdomains tend to cause fewer problems.

Answered By CrispHarbor8 On

Put a reverse proxy such as Caddy, Nginx, or Traefik in front of everything. It should be the only service publishing ports 80 and 443, terminate HTTPS, and forward requests over an internal Docker network to the appropriate container. The application containers themselves do not need to publish ports directly to the internet. Subdomains like site1.example.com and site2.example.com are usually easier than paths because many applications assume they are installed at /.

Answered By AmberMosaic6 On

Treat containers as replaceable. Keep databases and uploaded files in separate services or persistent volumes, and avoid relying on files stored only in the container filesystem. Ideally, have applications write logs to stdout and stderr, then use Docker’s logging configuration or a centralized system such as Loki to collect them. If you use Docker’s default JSON logging, configure rotation with limits like max-size and max-file so a busy site cannot fill the disk. For private or sensitive services, a managed tunnel and access-control layer can also avoid exposing the server directly, but a reverse proxy is the usual setup for public websites.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.