Snippet to add Hugo to Dockerfile

Netlify and co provide decent Docker images to build Hugo sites. However, I needed my own Docker build image and wanted to share with you my Dockerfile snippet with you.

The snippet:

  1. downloads the desired Hugo version
  2. verifies the checksum
  3. single RUN command
2 Likes

I created a Docker image for the Hugo extended, too. The base image is debian:9-slim and the total image size (171MB) is smaller than cibuilds/hugo

The following Dockerfile is used by my project (GitHub Actions) peaceiris/actions-hugo

FROM debian:9-slim

ENV HUGO_VERSION='0.55.6'
ENV HUGO_NAME="hugo_extended_${HUGO_VERSION}_Linux-64bit"
ENV HUGO_URL="https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_NAME}.deb"
ENV BUILD_DEPS="wget"

RUN apt-get update && \
    apt-get install -y git "${BUILD_DEPS}" && \
    wget "${HUGO_URL}" && \
    apt-get install "./${HUGO_NAME}.deb" && \
    rm -rf "./${HUGO_NAME}.deb" "${HUGO_NAME}" && \
    apt-get remove -y "${BUILD_DEPS}" && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "/usr/local/bin/hugo" ]

For your information.

1 Like

Thanks for your contribution. But I wanted to share a snippet for everyone to use in their own Dockerfile and not provide a new complete Docker image to the many existing ones.

If size is your concern, take a look at alpine or similar.
GitHub - klakegg/docker-hugo: Truly minimal Docker images for Hugo open-source static site generator. 8.9MB
GitHub - solidnerd/docker-hugo: A dockerized hugo image 24.3MB
GitHub - jojomi/docker-hugo: Docker image for hugo static page generator (https://gohugo.io) ~20MB

For your information.

1 Like

That is not provided as a public docker image. You cannot use it by docker pull
I just posted it as a Dockerfile snippet.

Thanks to you @arubacao, I finally have found small docker images for Hugo extended! I didn’t know how to build the Hugo extended version on alpine image.
Thank you for sharing the links!

(I tried those alpine base images, but those have some problems.)