this post was submitted on 05 Mar 2024
51 points (91.8% liked)

Selfhosted

39151 readers
305 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

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:

  1. BusyBox in a selfmade Docker container, manually running httpd or The smallest Docker image ...
  2. php:latest (ignoring the fact, that the built-in webserver is meant for development and not for production)
  3. 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?

you are viewing a single comment's thread
view the rest of the comments
[–] CameronDev@programming.dev 6 points 6 months ago (1 children)

Having PHP installed is just unnecessary attack surface.

Are you really struggling for space that 50mb matters? An 8gb usb can hold thar 160x?

[–] Dirk@lemmy.ml 1 points 6 months ago (1 children)

Having PHP installed is just unnecessary attack surface.

Yes! Especially running it's built-in webserver outside your dev environment. They "advertise" doing so in their Docker packages documentation, though. Every project without PHP is a good project. It's still an option - at least technically.

Are you really struggling for space that 50mb matters?

In a way, yes. I just want to optimize my stuff as much as possible. No unneeded tools, no overhead, a super clean environment, etc. Firing up another Nginx container just doesn't feel right anymore. (Even if it seems to be possible to manually "hack" file serving into NPM - which makes it a multi-use container serving various different sites and proxying requests.)

The machine I use as docker host also has a pretty low-end CPU and measly 4 gigabytes of RAM. So every resource not wasted is a good resource.

[–] CameronDev@programming.dev 1 points 6 months ago (1 children)

RAM is not the same as storage, that 50mb docker image isn't going to require 50mb of ram to run. But don't let me hold you back from your crusade :D

[–] Dirk@lemmy.ml 1 points 6 months ago (1 children)

Thanks for educating me on basic computer knowledge! 🤣

Applications need RAM, though. A full-fledged webserver with all the bells and whistles likely needs more ram than a specialized single-binary static file delivery server.

[–] CameronDev@programming.dev 1 points 6 months ago (1 children)

Sorry, wasn't meant to be condescending, you just seem fixated on file size when it sounds like RAM (and/or CPU?) is what you really want to optimise for? I was just pointing out that they arent necessarily correlated to docker image size.

If you really want to cut down your cpu and ram, and are okay with very limited functionality, you could probably write your own webserver to serve static files? Plain http is not hard. But you'd want to steer clear of python and node, as they drag in the whole interpreter overhead.

[–] Dirk@lemmy.ml 1 points 6 months ago (1 children)

I care about anything. RAM usage, file size, etc. I'm a minimalist when it comes to software. Use as less of all resources as possible. After once writing a router in Python I thought I could do this in Lua, too, but never actually tried. Maybe this would be a nice weekend project?

Even if Nginx is the way to go, I currently experiment with SWS which was suggested here. Technical aspects aside: The software is actively developed and the maintainer provides Docker images on their own (easy for Deploying a container based on that) and a package for my distribution (easy for development testing).

[–] pyrosis@lemmy.world 1 points 4 months ago

Well op look at it this way...

A single 50mb nginx docker image can be used multiple times for multiple docker containers.