用于静态网站的最小Docker镜像 - lipanski


这是一个单二进制、超小型、静态文件服务器。
静态文件服务器选择了thttpd,它具有类似的小占用空间,但似乎经过了更多的实战测试。

FROM alpine:3.13.2

# Install thttpd
RUN apk add thttpd

# Create a non-root user to own the files and run our server
RUN adduser -D static
USER static
WORKDIR /home/static

# Copy the static website
# Use the .dockerignore file to control what ends up inside the image!
COPY . .

# Run thttpd
CMD ["thttpd", "-D", "-h", "0.0.0.0", "-p", "3000", "-d", "/home/static", "-u", "static", "-l", "-", "-M", "60"]

运行thttpd是这样的:
thttpd -D -h 0.0.0.0 -p 3000 -d /static-website -u static-user -l - -M 60
这将在前台 ( -D) 中启动服务器,监听主机0.0.0.0( -h) 和端口3000( ),提供( ) 内( ) 可访问的-p所有文件。它会将访问日志打印到( ) 并将标题设置为秒 ( )。还有一些其他简洁的功能,例如基本身份验证、限制和虚拟主机,您可以在文档中阅读。/static-website-dstatic-user-uSTDOUT-l -Cache-Control60-M