Developing themes and building sites with Docker Compose.
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.
And then create docker-compose.yml
on your project root.
1name: mysite
2
3services:
4 server:
5 image: hugomods/hugo:exts-non-root
6 command: server -D
7 volumes:
8 - ./:/src
9 - ~/hugo_cache:/tmp/hugo_cache
10 ports:
11 - 1313:1313
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.
-v ./:/src
mounts current working directory on the default working directory(/src
) inside the Docker container.-v ~/hugo_cache:/tmp/hugo_cache
mounts $HOME/hugo_cache
on the default cacheDir
(/tmp/hugo_cache
) to improve build performance.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 compose run server npm i
npm i
replaces the default command of server
service, which is the shorthand of npm install
.1docker compose up server
1docker compose run server /bin/sh