Self-hosted static website using Docker

Since I was already migrating all projects running on my server into Docker containers, of course my private homepage needed to be migrated as well. This homepage is just a very basic static HTML page. This makes it rather easy to create a Docker container for it.┬áSo what I’m in the end just doing, is using a plain nginx image and injecting my homepage source code into the appropriate folder (/var/www/html).

I’m hosting my homepage source code on my private GitLab instance, which I clone into the same folder, where my docker-compose.yml is located. By defining the path to this cloned repository as a Docker volume mounted to /var/www/html, the configured nginx shows my homepage by default.

Apart from that, I added a nginx.conf file, mostly specifying nginx’ root folder and the server name.

worker_processes 1;

events { worker_connections 1024; }

http {
  server {
    root /var/www/html;
    server_name localhost domain.net www.domain.net;
  }
}
version: "3"

networks:
  proxy:
    external: true
  internal:
    external: false

services:
  homepage:
    image: nginx:1.15.2
    restart: always
    hostname: 'domain.net'
    volumes:
      - ./public_html:/var/www/html # the cloned repository
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    labels:
      - traefik.enable=true
      - traefik.backend=domain.net
      - traefik.admin.frontend.rule=Host:domain.net
      - traefik.docker.network=proxy
    networks:
      - internal
      - proxy
Leave a Reply

Your email address will not be published. Required fields are marked *