Developing With Docker Compose

Developing themes and building sites with Docker Compose.

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.

Create Docker Compose File

And then create docker-compose.yml on your project root.

docker-compose.yml
 1name: my-site
 2
 3services:
 4  server:
 5    image: hugomods/hugo:exts
 6    command: hugo server --bind 0.0.0.0
 7    volumes:
 8      - $PWD:/src
 9      - $HOME/hugo_cache:/tmp/hugo_cache
10    ports:
11      - 1313:1313
  1. ${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.

Install Dependencies (Optional)

You may want to install the dependencies before running Hugo server, such as install dependencies via npm.

1docker compose run server npm i
  1. npm i replaces the default command of server service, which is the shorthand of npm install.

Start Hugo Server

1docker compose up server