Developing With Docker Run

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-non-root as the example.

Change Current Working Directory

Change current working directory to your project root.

1cd mysite

Launch Interactive Shell

With the interactive shell, you’re able to:

  1. Install dependencies via NPM/Yarn.
  2. Create content.
  3. Update and tidy Hugo modules.
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
  1. -v ${PWD}:/src mounts current working directory on the default working directory(/src) inside the Docker container.
  2. $HOME/hugo_cache:/tmp/hugo_cache mounts $HOME/hugo_cache on the default cacheDir (/tmp/hugo_cache) to improve build performance.

Start Hugo 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
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
  1. -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

Stop Hugo Server

1docker stop mysite

Attach Hugo Server

Attach to a running Hugo server.

1docker start -a mysite