Run Hugo with Docker

Run Hugo with Docker (without installing Hugo on your workstation).

from: https://hub.docker.com/r/jguyomard/hugo-builder/

docker run --rm -it jguyomard/hugo-builder hugo help

Create a new Hugo managed website

docker run --rm -it -v ${PWD}:/src -u hugo jguyomard/hugo-builder hugo new site mysite

then

cd mysite

Add a Theme

Now, you probably want to add a theme (see https://themes.gohugo.io/ )

git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke;
echo 'theme = "ananke"' >> config.toml

Add some Content

docker run --rm -it -v ${PWD}:/src -u hugo jguyomard/hugo-builder hugo new posts/my-first-post.md

Now, you can edit this post, add your content and remove “draft” flag:

NOTE: “xdg-open” is an editor. You can open the file with whichever editor you choose.

xdg-open content/posts/my-first-post.md

Build your site

docker run --rm -it -v ${PWD}:/src -u hugo jguyomard/hugo-builder hugo

Serve your site locally:

docker run --rm -it -v ${PWD}:/src -p 1313:1313 -u hugo jguyomard/hugo-builder hugo server -w --bind=0.0.0.0

Then open http://localhost:1313/ in your browser.

Handy aliases

alias hugo="docker container run --rm -it -v ${PWD}:/src -u hugo jguyomard/hugo-builder hugo"
alias hugo-serve="docker container run --rm -it -p 1313:1313 -v ${PWD}:/src --user hugo jguyomard/hugo-builder hugo serve -w --bind=0.0.0.0"

With these aliases, you can run the commands on this page with hugo and hugo-serve