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?

  • CameronDev@programming.dev
    link
    fedilink
    English
    arrow-up
    3
    ·
    4 months ago

    Just go nginx, anything else is faffing about. Busybox may not be security tested, so best to avoid on the internet. Php is pointless when its a static site with no php. Id avoid freenginx until its clear that it is going to be supported. There is nothing wrong with stock nginx, the fork is largely political rather than technical.

    • 𝘋𝘪𝘳𝘬@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      4 months ago

      Php is pointless when its a static site with no php

      Absolutely, but it has a built-in webserver that can serve static files, too (I constantly use that in my dev environment).

      But I guess you’re mostly right about just using Nginx. I already have multiple containers running it, though. Most of them just serving static files. But it’s ca. 50 megabytes compressed size each container just for Nginx alone.

      • CameronDev@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 months ago

        Having PHP installed is just unnecessary attack surface.

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

        • 𝘋𝘪𝘳𝘬@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          0
          ·
          4 months ago

          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
            link
            fedilink
            English
            arrow-up
            0
            ·
            4 months ago

            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

            • 𝘋𝘪𝘳𝘬@lemmy.mlOP
              link
              fedilink
              English
              arrow-up
              0
              ·
              4 months ago

              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
                link
                fedilink
                English
                arrow-up
                0
                ·
                4 months ago

                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.

                • 𝘋𝘪𝘳𝘬@lemmy.mlOP
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  4 months ago

                  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).

  • CetaceanNeeded@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 months ago

    I just use nginx alpine, if freenginx proves to be the better option later it should be fairly trivial to switch the base image.

    • 𝘋𝘪𝘳𝘬@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      4 months ago

      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.

  • Sockenklaus@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 months ago

    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.

    • 𝘋𝘪𝘳𝘬@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 months ago

      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).

  • marcos@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 months ago

    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.

  • Decronym@lemmy.decronym.xyzB
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:

    Fewer Letters More Letters
    Git Popular version control system, primarily for code
    HTTP Hypertext Transfer Protocol, the Web
    SSL Secure Sockets Layer, for transparent encryption
    nginx Popular HTTP server

    4 acronyms in this thread; the most compressed thread commented on today has 14 acronyms.

    [Thread #575 for this sub, first seen 5th Mar 2024, 14:15] [FAQ] [Full list] [Contact] [Source code]

  • sudneo@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 months ago

    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.

  • ptman@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 months ago

    Forget about docker. Run caddy or some similar webserver that is a single file next to the assets to serve.

    • sudneo@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 months ago

      Containers are a perfectly suitable use-case for serving static sites. You get isolation and versioning at the absolutely negligible cost of duplicating a binary (the webserver - which in case of the one I linked in my comment, it’s 5MB of space). Also, you get autostart of the server if you use compose, which is equivalent to what you would do with a Systemd unit, I suppose.

      You can then use a reverse-proxy to simply route to the different containers.

  • Swarfega@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 months ago

    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.

  • Possibly linux@lemmy.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 months ago

    If your looking for a small size you could build a custom image with buildroot and lighttpd. It is way, way overkill but it would be the smallest.

    For something easier use the latest image of your web server of choice and then pass though a directory with the files. From there you can automate patching with watch tower.

    • okamiueru@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      4 months ago

      First thing you mention is such a fun and useful exercise. But as you point out, way overkill. Might even be dangerous to expose it. I got mine to 20kb on top of busybox.

      There is something that tickles the right spots when a complete container image significantly smaller than the average js payload in “modern” websites.