This guide uses Docker to run Lighttpd web server.
For Docker installation, see Docker.
Create a directory to store your configuration and compose files.
mkdir -p /opt/lighttpd
cd /opt/lighttpd
Define a container for Lighttpd.
Note: There is no official Lighttpd Docker image. Use community-maintained images or build your own.
services:
lighttpd:
image: sebp/lighttpd:latest # Community-maintained image
container_name: lighttpd
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/var/www/localhost/htdocs
- ./config/lighttpd.conf:/etc/lighttpd/lighttpd.conf
- ./log:/var/log/lighttpd
restart: unless-stopped
Alternative Images:
sebp/lighttpd:latest - Popular community image (Debian-based)lighttpd/lighttpd:1.4 - If available (check Docker Hub)mkdir -p /opt/lighttpd/html
echo "<h1>Lighttpd in Docker</h1>" > /opt/lighttpd/html/index.html
mkdir -p /opt/lighttpd/config
Create /opt/lighttpd/config/lighttpd.conf:
server.modules = (
"mod_access",
"mod_accesslog"
)
server.document-root = "/var/www/localhost/htdocs"
server.port = 80
server.errorlog = "/var/log/lighttpd/error.log"
index-file.names = ( "index.html", "index.htm" )
dir-listing.activate = "disable"
server.username = "lighttpd"
server.groupname = "lighttpd"
Start the container in the background.
docker compose up -d
docker compose ps
docker logs lighttpd
Test the web server:
curl -I http://localhost
For production use, configure TLS:
services:
lighttpd:
image: sebp/lighttpd:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/var/www/localhost/htdocs
- ./config:/etc/lighttpd
- ./ssl:/etc/ssl/lighttpd # SSL certificates
restart: unless-stopped
Update lighttpd.conf for HTTPS:
server.modules += ( "mod_openssl" )
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/ssl/lighttpd/server.pem"
ssl.ca-file = "/etc/ssl/lighttpd/ca.pem"
}
Create Dockerfile:
FROM alpine:latest
RUN apk add --no-cache lighttpd lighttpd-mod_openssl
COPY config/lighttpd.conf /etc/lighttpd/lighttpd.conf
COPY html/ /var/www/localhost/htdocs/
EXPOSE 80 443
CMD ["lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"]
Build and run:
docker build -t my-lighttpd .
docker run -d -p 80:80 -p 443:443 my-lighttpd
# View logs
docker compose logs -f lighttpd
# Stop container
docker compose down
# Restart container
docker compose restart
# Execute commands inside container
docker exec -it lighttpd lighttpd --version
docker exec -it lighttpd lighttpd -tt -f /etc/lighttpd/lighttpd.conf
sebp/lighttpd:latest is a popular Debian-based optiondocker exec lighttpd lighttpd --version# Check container status
docker compose ps
# View logs
docker compose logs lighttpd
# Test configuration
docker exec lighttpd lighttpd -tt -f /etc/lighttpd/lighttpd.conf
# Restart if needed
docker compose restart lighttpd
# Check file permissions
docker exec lighttpd ls -la /var/www/localhost/htdocs
Deploying Lighttpd in containers for production? Our consulting covers:
Get expert help: office@linux-server-admin.com | Contact Page