Developing themes and building sites with Docker run.
Firstly, you’ll need to choose the proper image tag for your themes and sites, in this section, we take hugomods/hugo:exts
as the example.
Change current working directory to your project root.
1cd my-site
The rest of steps are performed under your project root.
Skip this step if your site/theme doesn’t require it.
You may want to install the dependencies before running Hugo server, such as install dependencies via npm.
1docker run \
2 -v ${PWD}:/src \
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
4 hugomods/hugo:exts \
5 npm i
1docker run `
2 -v ${PWD}:/src `
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
4 hugomods/hugo:exts `
5 npm i
-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.npm i
replaces the default command(hugo version
), which is the shorthand of npm install
.1docker run -p 1313:1313 \
2 -v ${PWD}:/src \
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
4 hugomods/hugo:exts \
5 hugo server --bind 0.0.0.0
1docker run -p 1313:1313 `
2 -v ${PWD}:/src `
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
4 hugomods/hugo:exts `
5 hugo server --bind 0.0.0.0
Please note that --bind 0.0.0.0
is required, otherwise Hugo server may not receive any incoming requests from host.
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 -p 8080:8080 \
2 -v ${PWD}:/src \
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache \
4 hugomods/hugo:exts \
5 hugo server --bind 0.0.0.0 -p 8080
1docker run -p 8080:8080 `
2 -v ${PWD}:/src `
3 -v ${HOME}/hugo_cache:/tmp/hugo_cache `
4 hugomods/hugo:exts `
5 hugo server --bind 0.0.0.0 -p 8080