Minimal web server docker containers

      No Comments on Minimal web server docker containers


We often need a simple web server as a Docker container to serve up static content (HTML or an Angular app etc). Most people are using lighttpd or nginx for this purpose (both are fast and lightweight). So in this post I’ll take you through the process of creating a minimal Docker container using lighttpd and then one using nginx. In each case, for demonstration purposes, we’ll just serve up a single index.html file.


$ mkdir lighttpd
$ cd lighttpd
$ echo "hello world from lighttpd" > index.html
$ more Dockerfile
FROM alpine

RUN apk update \
    && apk add lighttpd \
    && rm -rf /var/cache/apk/*

COPY ./index.html /var/www/localhost/htdocs

CMD ["lighttpd","-D","-f","/etc/lighttpd/lighttpd.conf"]
$ docker build . -t lighttpd
$ docker run -d --name lighttpd -p 8080:80 lighttpd


$ mkdir nginx
$ cd nginx
$ echo "hello world from nginx" > index.html
$ more Dockerfile
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /www
COPY ./index.html /www
$ more nginx.conf
$ more nginx.conf
events {
    worker_connections  1024;

http {
    server {
        root /www/;
$ docker build . -t nginx
$ docker run -d --name nginx -p 8081:80 nginx

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.