Create hugo site with docker
Create a Hugo site and run it from Docker without installing Hugo on the host.
Add the Hugo Docker image
Save this as Dockerfile in an empty working folder:
FROM ubuntu
RUN apt update && apt install hugo -y
WORKDIR /site
ENTRYPOINT [ "hugo", "-D" ]
Build the image:
docker build -t hugo .
Create the site from Docker
Create the site:
docker run --rm \
-v "$(pwd)":/work \
-w /work \
--entrypoint hugo \
hugo new site my-site
The site root is my-site/.
Configure the theme
Hugo loads themes from the themes/ folder inside the site root.
If the config contains:
theme: "vanilla"
Hugo looks for this folder:
my-site/
themes/
vanilla/
Clone or copy the theme into that exact path:
git clone https://github.com/zwbetz-gh/vanilla-bootstrap-hugo-theme my-site/themes/vanilla
The folder name must match the theme value.
Configure the site
Hugo reads the site config from the site root. With YAML, use my-site/config.yaml or my-site/hugo.yaml.
Set theme and publishDir as top-level keys:
baseURL: "http://localhost:1313"
languageCode: "en-us"
title: "My Hugo Site"
theme: "vanilla"
publishDir: "../site-output"
theme tells Hugo which folder to load from themes/.
publishDir tells Hugo where to write the generated site. The path is relative to the site root. If omitted, Hugo writes to public/.
Run the local server
Start the development server:
docker run --rm -it \
-v "$(pwd)/my-site":/site \
-p 1313:1313 \
--entrypoint hugo \
hugo serve --bind 0.0.0.0 --source /site --buildDrafts --watch
The site is available at http://localhost:1313.
Generate the static site
If publishDir stays inside the site root, build with:
docker run --rm \
-v "$(pwd)/my-site":/site \
--entrypoint hugo \
hugo --source /site
If publishDir points outside the site root, mount the parent folder that contains both the site and the output path:
docker run --rm \
-v "$(pwd)":/work \
--entrypoint hugo \
hugo --source /work/my-site
This writes the generated files to the path defined in publishDir.