I’m currently researching the best method for running a static website from Docker.
The site consists of one single HTML file, a bunch of CSS files, and a few JS files. On server-side nothing needs to be preprocessed. The website uses JS to request some JSON files, though. Handling of the files is doing via client-side JS, the server only need to - serve the files.
The website is intended to be used as selfhosted web application and is quite niche so there won’t be much load and not many concurrent users.
I boiled it down to the following options:
- BusyBox in a selfmade Docker container, manually running
httpd
or The smallest Docker image … php:latest
(ignoring the fact, that the built-in webserver is meant for development and not for production)- Nginx serving the files (but this)
For all of the variants I found information online. From the options I found I actually prefer the BusyBox route because it seems the cleanest with the least amount of overhead (I just need to serve the files, the rest is done on the client).
Do you have any other ideas? How do you host static content?
The answer is get a minimum linux image, add nginx or apache, and put your content on the relevant place. (Basically, your third option.)
Do not bother about the future of nginx. Changing the web server on that image is the easiest thing in the world.
I just use nginx in docker. It runs from a Pi4 so needs to be lightweight. I’m sure there are lighter httpd servers to use, but it works for me. I also run nginx proxy manager to create a reverse proxy and to manage the certificate renewal that comes from Let’s Encrypt.
I personally package the files in a scratch or distroless image and use https://github.com/static-web-server/static-web-server, which is a rust server, quite tiny. This is very similar to nginx or httpd, but the static nature of the binary removes clutter, reduces attack surface (because you can use smaller images) and reduces the size of the image.
Thanks, this looks actually pretty great. From the description it’s basically BusyBox httpd but with Nginx stability and production-readiness and functionality. It also seems to be actively developed.
I just use nginx alpine, if freenginx proves to be the better option later it should be fairly trivial to switch the base image.
Yes, Freenginx should/would/will be a drop-in replacement, at least int he beginning. We’ll see how this works out over time. Forks purely out of frustration never lived long enough to gain a user base and attract devs. But it’s an “anti corporate bullshit” fork and this alone puts it on my watchlist.
Err,
FROM webserver
+COPY /path/to/content /path/to/server/directory
? You don’t event expect users, what’s there to discuss?I’ve always used an nginx alpine image and have been very happy with it.
Not sure how this fork business is turning out and I have also heard conflicting opinions on wether to care or not…
If you do wish for something simple that is not nginx I’m also very happy with caddy, which can also handle ssl certificates for you, if you plan to make it publicly reachable.
I’ve read that you’re trying for minimal resource overhead.
Is lighttpd still a thing? Back in the day I used it to deliver very simple static Http pages with minimal resource usage.
I found a docker image with like 4 mb size but being two years old I don’t know how well maintained lighttpd is these days.
The old age of the Docker image is a bit of a red flag to me.
I settled with SWS since the Docker image and a locally installable version are actively maintained by the creator. It just serves static files and optionally directory listing as JSON (which comes in quite handy).