The new hugo server is now started.
Dockerfile used (the simplest solution with downloading prepared .deb package):
FROM ubuntu:latest
# check new releases on https://github.com/gohugoio/hugo/releases
RUN apt update \
&& apt -y install git wget lsof htop net-tools bash \
&& wget https://github.com/gohugoio/hugo/releases/download/v0.55.6/hugo_0.55.6_Linux-64bit.deb -O hugo.deb \
&& dpkg -i hugo.deb \
&& rm hugo.deb
ENTRYPOINT hugo server --baseUrl=mszuyev.xyz --bind='0.0.0.0' --appendPort=false
Nginx config to reverse proxy (simplest method)
server {
listen 80;
server_name hugo.mszuyev.xyz;
location / {
#proxy_set_header X-Forwarded-For $remote_addr;
#proxy_set_header Host $http_host;
proxy_pass http://172.18.0.120:1313;
}
}
How to start
The starting is a bit tricky, because Hugo refuses to work if the main site was not initialized. So, to start it under Docker, just do the following process:
Comment ENTRYPOINT section in the Dockerfile, build and run container
While running, initialize the site, then drop image
Uncomment entrypoint and build container again (with entrypoint) and enjoy running Hugo
In more details:
Step 1:
open the Dockerfile and comment ENTRYPOINT in it
run in console:
docker build -t hugo .
Step 2:
- when build finishes, run this image:
docker container run -u $(id -u):$(id -g) -v $HUGO_ROOT:/hugo --rm -it hugo /bin/sh
.
Here $HUGO_ROOT should be the path to your hugo root (not to site root) at the host machine. The same folder you should use as volume while running Hugo site in the end. For example, HUGO_ROOT=/home/mszuyev/docker/roots/www/hugo
then, run in container:
hugo new site $SITE_NAME cd /hugo/$SITE_NAME/themes git init git submodule add https://github.com/htr3n/hyde-hyde.git exit
The $SITE_NAME here is the name of your site and also the name of the site’s folder. For example, SITE_NAME=mszuyev
- then copy or add site content to created dirs. The main thing you need is config.toml file with settings, content dir with your posts and static dir with static files (images, etc).
Note: Currently Hugo can’t handle soft links, so just copy the content if you have it, don’t do ln -s
.
- finally, remove intermediate container:
docker rmi -f hugo
Step 3:
- open the Dockerfile and uncomment ENTRYPOINT section back
docker-compose up -d
At this point your Hugo site is ready (ok, should be ready).
docker-compose.yaml part to run Hugo
hugo:
build: conf/hugo
image: hugo
container_name: hugo
user: 1000:1000 # $(id -u):$(id -g)
restart: on-failure
working_dir: /hugo_sites/mszuyev
volumes:
- ./roots/www/hugo:/hugo_sites:rw