In this blog post, we’ll explore how to use Docker and the lightweight HTTP server, Darkhttpd, to serve static files. This setup is particularly useful when you need a simple web server for sharing files or hosting a static website. We’ll also discuss how to use a reverse proxy like Traefik to route external traffic to the Darkhttpd service.
Docker Compose Configuration
Below is the
docker-compose.yml file that defines the Darkhttpd service:
version: '3.3' services: darkhttpd: image: p3terx/darkhttpd container_name: darkhttpd restart: unless-stopped volumes: - './site:/www:ro' entrypoint: ["/darkhttpd","/www"] networks: your_network: ipv4_address: your_ipv4_address networks: your_network: external: name: your_network_name
Here’s a brief overview of the configuration:
imagefield specifies the Docker image to use for the service.
container_namefield sets the name of the container.
restartfield configures the restart policy for the container.
volumesfield defines the volume mounts for the service.
entrypointfield overrides the default entrypoint of the image.
networksfield specifies the networks that the service is connected to.
Setting Up the Service
- Create a directory named
sitein the same directory as the
docker-compose.ymlfile. Place the static files you want to serve in this directory.
docker-compose.ymlfile with the appropriate values for your setup.
- Run the following command to start the Darkhttpd service:
docker-compose up -d
- Access the static files by navigating to the IP address specified in the
Using a Reverse Proxy
To route external traffic to the Darkhttpd service, you can use a reverse proxy like Traefik. Configure the reverse proxy to forward requests to the IP address specified in the
Using Docker and Darkhttpd to serve static files is a simple and efficient solution for sharing files or hosting a static website. By adding a reverse proxy, you can easily route external traffic to the Darkhttpd service. This setup is ideal for scenarios where you need a lightweight web server without the overhead of a full-fledged web server like Apache or Nginx.