Latest Hugo Docker images

Are you tired of constantly searching for new Docker images every time there’s a new HUGO version? Here’s my custom Dockerfile snippet.

FROM docker.io/library/golang:1.20-alpine

RUN apk add --no-cache \
    curl \
    gcc \
    g++ \
    musl-dev \
    build-base \
    libc6-compat

ARG HUGO_VERSION

RUN mkdir $HOME/src && \
    cd $HOME/src && \
    curl -L https://github.com/gohugoio/hugo/archive/refs/tags/v${HUGO_VERSION}.tar.gz | tar -xz && \
    cd "hugo-${HUGO_VERSION}" && \
    go install --tags extended

FROM docker.io/library/golang:1.20-alpine

RUN apk add --no-cache \
    runuser \
    git \
    openssh-client \
    rsync \
    npm && \
    npm install -D autoprefixer postcss-cli

RUN mkdir -p /var/hugo && \
    addgroup -Sg 1000 hugo && \
    adduser -Sg hugo -u 1000 -h /var/hugo hugo && \
    chown -R hugo: /var/hugo && \
    runuser -u hugo -- git config --global --add safe.directory /src

COPY --from=0 /go/bin/hugo /usr/local/bin/hugo

WORKDIR /src

USER hugo:hugo

EXPOSE 1313

Build Docker image using:

docker build -t my-hugo-image --build-arg HUGO_VERSION=<version> .

Replace <version> with the desired version of Hugo, for example, 0.92.0

After the image is built successfully, you can run a container based on this image:
docker run -p 1313:1313 my-hugo-image

1 Like

I’ve been using the images from hugomods: Image Tags - Docs - Hugo Docker Images | HugoMods

They are quite comprehensive, from the minimalist to the ones that encompass everything.