Dockerize (#3)

Add static build option to Makefile and create Dockerfile to run it.
This commit is contained in:
Miles Elam 2021-04-03 00:08:52 -07:00 committed by GitHub
parent 9222bbc9d8
commit 35c488b95f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

16
Dockerfile Normal file
View File

@ -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 ["."]

View File

@ -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

View File

@ -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.