A very small Docker image (~100KB) to run any static website, based on the BusyBox httpd static file server.
This repo is based on the similar one by @lipanski found here: docker-static-website.
However instead of compiling busybox
from source, this one is pulling the prebuilt binaries provided by busybox
themselves.
The container image can be built and run using similar instructions found in the original README. The contents are quoted below.
To use this container image, use this FROM
instruction:
FROM ghcr.io/jason-clark-fg/docker-static-site:main
To build this container, run:
docker build --platform linux/amd64 --tag docker-static-site .
You can use this container directly to serve an html
file from the local filesystem by using a volume mount. For instance, if you have your index.html
in the current directory, you can use the following:
docker run --platform linux/amd64 -it --init --rm -p 3000:3000 -v ${PWD}/index.html:/home/static/index.html --name docker-static-site docker-static-site
NOTE: The --platform
flag may, or may not be required, depending on the platform you are building on and for.
NOTE: The precompiled version of busybox_HTTPD
does not support gzipped
files as well the compiled one.
Original README:
A very small Docker image (~154KB) to run any static website, based on the BusyBox httpd static file server.
If you're using the previous version (1.x, based on thttpd), I recommend upgrading since the new version (2.x) comes with a much smaller memory footprint.
For more details, check out my article.
The image is hosted on Docker Hub:
FROM lipanski/docker-static-website:latest # Copy your static files COPY . .Build the image:
docker build -t my-static-website .
Run the image:
docker run -it --rm -p 3000:3000 my-static-websiteBrowse to
http://localhost:3000
.If you need to configure the server in a different way, you can override the
CMD
line:FROM lipanski/docker-static-website:latest # Copy your static files COPY . . CMD ["/busybox", "httpd", "-f", "-v", "-p", "3000", "-c", "httpd.conf"]NOTE: Sending a
TERM
signal to your TTY running the container won't get propagated due to how busybox is built. Instead you can calldocker stop
(ordocker kill
> if can't wait 15 seconds). Alternatively you can run the container withdocker run -it --rm --init
which will propagate signals to the process correctly.For every file that should be served gzipped, add a matching
[FILENAME].gz
to your image.Add a
httpd.conf
file and use theP
directive:P:/some/old/path:[http://]hostname[:port]/some/new/path
Add a
httpd.conf
file and use theE404
directive:E404:e404.html
...where
e404.html
is your custom 404 page.Note that the error page directive is only processed for your main
httpd.conf
file. It will raise an error if you use it inhttpd.conf
files added to subdirectories.Add a
httpd.conf
file and use theA
andD
directives:A:172.20. # Allow address from 172.20.0.0/16 A:10.0.0.0/25 # Allow any address from 10.0.0.0-10.0.0.127 A:127.0.0.1 # Allow local loopback connections D:* # Deny from other IP connections
You can also allow all requests with some exceptions:
D:1.2.3.4 D:5.6.7.8 A:* # This line is optional
Add a
httpd.conf
file, listing the paths that should be protected and the corresponding credentials:/admin:my-user:my-password # Require user my-user with password my-password whenever calling /admin
Read the source code comments.
Clone the busybox repo and create a blank config:
make allnoconfig
Copy the resulting
.config
to this project, diff it against the old one and re-enable everything that seems reasonable (mostly theHTTPD
features).Uncomment the
COPY . .
line in theDockerfile
, add a dummyindex.html
and build a test image:docker build -t docker-static-website-test .
Then run it:
docker run -it --rm --init -p 3000:3000 docker-static-website-test
Browse to
http://localhost:3000
and check that the contents of theindex.html
file were rendered correctly.Build the image:
docker build -t lipanski/docker-static-website:1.2.3 .
Push the image to Docker Hub:
docker push lipanski/docker-static-website:1.2.3
Tag the release:
git tag 1.2.3 git push --tags
Enjoy! 😄