This guide uses Docker Compose to build Hugo sites and serve the generated static files.
For Docker installation, see Docker.
There is no official Hugo Docker image, but community images are available:
klakegg/hugo - Popular Hugo build imagegohugo/hugo - Community-maintained imagemkdir hugo-site
cd hugo-site
Create docker-compose.yml for building and serving:
cat <<'YAML' > docker-compose.yml
services:
hugo:
image: klakegg/hugo:0.158.0
command: server -D --bind 0.0.0.0
volumes:
- ./site:/src
ports:
- "1313:1313"
web:
image: nginx:alpine
restart: unless-stopped
depends_on:
- hugo
ports:
- "8080:80"
volumes:
- ./site/public:/usr/share/nginx/html:ro
YAML
# Create Hugo site using Docker
docker compose run --rm hugo new site .
# Or if you have existing site, place files in ./site directory
# Enter Hugo container
docker compose run --rm hugo
# Inside container, add theme
cd /src
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
# Development server (port 1313)
docker compose up hugo
# Production build
docker compose run --rm hugo --minify
# Serve with Nginx (port 8080)
docker compose up web
For simple build workflow:
cat <<'YAML' > docker-compose.yml
services:
hugo:
image: klakegg/hugo:0.156.0
volumes:
- ./site:/src
command: --minify
YAML
Build:
docker compose run --rm hugo
Output in site/public/ directory.
| Mount | Purpose |
|---|---|
./site:/src |
Hugo source files |
./site/public:/usr/share/nginx/html |
Generated static files |
For production, build once and deploy static files:
# Build production site
docker compose run --rm hugo --minify
# Copy public/ to web server
rsync -avz site/public/ user@server:/var/www/html/
💼 Professional Services: Need expert help with your Hugo Docker deployment? We offer consulting, training, and support. Contact our team →