FROM alpine:3.15.0 AS builder ARG THTTPD_VERSION=2.29 # Install all dependencies required for compiling thttpd RUN apk add gcc musl-dev make # Download thttpd sources RUN wget http://www.acme.com/software/thttpd/thttpd-${THTTPD_VERSION}.tar.gz \ && tar xzf thttpd-${THTTPD_VERSION}.tar.gz \ && mv /thttpd-${THTTPD_VERSION} /thttpd # Compile thttpd to a static binary which we can copy around RUN cd /thttpd \ && ./configure \ && make CCOPT='-O2 -s -static' thttpd # Create a non-root user to own the files and run our server RUN adduser -D static # Switch to the scratch image FROM scratch EXPOSE 80 # Copy over the user COPY --from=builder /etc/passwd /etc/passwd # Copy the thttpd static binary COPY --from=builder /thttpd/thttpd / # Use our non-root user 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", "80", "-d", "/home/static", "-u", "static", "-l", "-", "-M", "60"]