When building an application with a web-frontend and backend, one can choose between:
- Deploying a single container, where the backend serves or renders the frontend
- Deploying a frontend and backend container, seperately.
When not building on top of containers, but serverless, for example, CDN services can be used
The best practice
Use separate containers. Docker Compose for example, can be used.
Serve the frontend in a webserver such as Nginx, Caddy etc.
- Webservers are very lean, thus almost no overhead
- The containers can be scaled individually
- One can take benefit of the advanced features for web servers, such as for routing, proxies, compression, Load balancing, auth etc. - especially Nginx offers deep configuration
- Builds can be cached more effectively