Sign inSign up

momar/web

By momar

•Updated almost 5 years ago

just serve static files.

Image
0

100K+

momar/web repository overview

⁠web: just serve static files.

This is a Docker image that's built for exactly a single thing: serving static files. Use it for your JAMstack⁠ applications, to serve your .well-known directory for Let's Encrypt, local development, or basically anything else that just requires a simple file server. It's built in under 100 lines of Go, using the awesome fasthttp⁠ library for extreme efficiency.

To get started, just run the following command to serve the current working directory on http://localhost:8080⁠:

docker run --rm -it -p 8080:80 -v "$PWD:/var/www:ro" momar/web

The following options (each shown with their default value) are configurable through environment variables (-e VARIABLE=value):

  • NOT_FOUND=/404.html - path to the 404 error page
  • NOT_FOUND_STATUS=404 - set a status code for the 404 error page (you can use "200" here for webapps based on the history API)
  • INDEX_FILES=index.html;index.htm - semicolon-separated list of files that should be served when accessing a directory
  • ENABLE_INDEX=0 - show a directory index if no index file could be found
  • ENABLE_HIDDEN=0 - allow access to files and directories starting with a dot
  • ENABLE_COMPRESSION=1 - enable gzip/deflate/brotli compression on-the-fly; you can also use the special value cached to create cached .fasthttp.gz files⁠, which is recommended when extending the image via a Dockerfile, and is not recommended when using volumes
  • ENABLE_RANGE=1 - enable HTTP range requests⁠
  • ENABLE_CORS=0 - enable CORS⁠ headers with Origin: *, Headers: Range and Methods: GET, HEAD
  • ENABLE_CACHE=1 - if set to 0, send a Cache-Control: no-cache⁠ header with each request (otherwise it will be set to must-revalidate)
  • ENABLE_DEBUG=0 - print all non-OK requests to standard output/docker logs
  • HOST=[::] & PORT=80 - listening address, doesn't normally have to be changed

I'm assuming that you're using Docker with a reverse proxy anyways if you want to use this, so this doesn't come with HTTPS support - if you need that, go with Caddy⁠, or add a Traefik 2⁠ to your setup.

This image is feature-complete and production-ready, and has been inspired by hastatic⁠ (which is unfortunately written in a really ugly programming language).

Also, doing a quick benchmark on a relatively bad computer with siege -b -c 100 -t 60S and access logs disabled on the example index.html file, it's extremely fast:

ServerCompressed image sizeRequests per secondResponse timeLongest transactionMemory consumption
momar/web2 MB5196.340.02 s0.22 s~11 KB
abhin4v/hastatic5 MB2466.330.04 s0.25 s~220 MB
nginx:alpine9 MB5272.680.02 s0.32 s~14 KB
httpd:alpine32 MB4555.740.02 s0.30 s~30 KB
caddy:alpine14 MB4400.650.02 s0.28 s~ 40 KB

Tag summary

Content type

Image

Digest

Size

1.7 MB

Last updated

almost 5 years ago

docker pull momar/web