diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..278ef0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Build environment +FROM alpine AS build +RUN apk add --no-cache build-base +WORKDIR /src +COPY . . +RUN make darkhttpd-static \ + && strip darkhttpd-static + +# Just the static binary +FROM scratch +WORKDIR /var/www/htdocs +COPY --from=build /src/darkhttpd-static /darkhttpd +EXPOSE 80 +ENTRYPOINT ["/darkhttpd"] +CMD ["."] + diff --git a/Makefile b/Makefile index 8fc9b18..87f4695 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,10 @@ all: darkhttpd darkhttpd: darkhttpd.c $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) darkhttpd.c -o $@ +darkhttpd-static: darkhttpd.c + $(CC) -static $(CFLAGS) $(LDFLAGS) $(LIBS) darkhttpd.c -o $@ + clean: - rm -f darkhttpd core darkhttpd.core + rm -f darkhttpd core darkhttpd.core darkhttpd-static darkhttpd-static.core .PHONY: all clean diff --git a/README.md b/README.md index cd85400..8cd2ef4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Features: * At some point worked on FreeBSD, Linux, OpenBSD, Solaris. * ISC license. * suckless.org says [darkhttpd sucks less](http://suckless.org/rocks/). +* Small Docker image (<100KB) Security: * Can log accesses, including Referer and User-Agent. @@ -142,4 +143,17 @@ run darkhttpd without any arguments: ./darkhttpd ``` +## How to run darkhttpd in Docker + +First, build the image. +``` +docker build -t darkhttpd . +``` +Then run using volumes for the served files and port mapping for access. + +For example, the following would serve files from the current user's dev/mywebsite directory on http://localhost:8080/ +``` +docker run -p 8080:80 -v ~/dev/mywebsite:/var/www/htdocs:ro darkhttpd +``` + Enjoy.