Developing themes and building sites with Docker run.
Become a backer or sponsor to support our work.
Firstly, you’ll need to choose the proper image tag for your themes and sites, in this section, we take hugomods/hugo:exts-non-root
as the example.
Change current working directory to your project root.
1cd mysite
The rest of steps are performed under your project root.
With the interactive shell, you’re able to:
1docker run -it \
2 -v ${PWD}:/src \
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
4 hugomods/hugo:exts-non-root \
5 /bin/sh
1docker run -it `
2 -v ${PWD}:/src `
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
4 hugomods/hugo:exts-non-root `
5 /bin/sh
-v ${PWD}:/src
mounts current working directory on the default working directory(/src
) inside the Docker container.$HOME/hugo_cache:/tmp/hugo_cache
mounts $HOME/hugo_cache
on the default cacheDir
(/tmp/hugo_cache
) to improve build performance.Warning
You might need to create the
${HOME}/hugo_cache
folder first viamkdir ${HOME}/hugo_cache
when running on *nix OS.Otherwise permission issues may arise.
1docker run --rm \
2 --name mysite \
3 -v ${PWD}:/src \
4 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
5 hugomods/hugo:exts-non-root \
6 server
1docker run --rm `
2 --name mysite `
3 -v ${PWD}:/src `
4 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
5 hugomods/hugo:exts-non-root `
6 server
Please note that --bind 0.0.0.0
is required when using hugo server
, otherwise Hugo server may not receive any incoming requests from host.
Since 0.136.2
, both of server
and hugo server
bind 0.0.0.0
by default.
Since 0.128.0
, server
is available as an alias of hugo server
, which will bind 0.0.0.0
by default.
-p port:port
mapping from host machine port to container port.Using another port than 1313
, such as 8080
.
1docker run --rm \
2 --name mysite \
3 -p 8080:8080 \
4 -v ${PWD}:/src \
5 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
6 hugomods/hugo:exts-non-root \
7 server -p 8080
1docker run --rm `
2 --name mysite `
3 -p 8080:8080 `
4 -v ${PWD}:/src `
5 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
6 hugomods/hugo:exts-non-root `
7 server -p 8080
1docker stop mysite
Attach to a running Hugo server.
1docker start -a mysite