- November 11, 2017
- 2 min read
Dockerizing Hugo Sites
Hugo is a great OSS project that can be used to create static sites that are based on markdown files stored in a git repository. My personal blog is created using hugo and hosted on AWS S3. I recently did some work to dockerize it and thought I'd write about it.
First thing I needed to do was create a docker image with hugo installed so I can build my hugo site. For more info on the docker image see the Dockerfile contents below, you can also check out the git repository here. As you can see from the below snippet, nothing major is going on here, I'm using golang alpine image as a base and then installing hugo and adding hugo to the system path.
FROM golang:1.8.3-alpine
ENV HUGO_VERSION 0.25
ENV HUGO_BINARY hugo_${HUGO_VERSION}_linux-64bit
ENV PATH=/usr/local/hugo:${PATH}
RUN set -x \
&& apk upgrade --update \
&& apk add --update ca-certificates bash curl wget \
&& rm -rf /var/cache/apk/* \
&& mkdir /usr/local/hugo \
&& wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY}.tar.gz -O /usr/local/hugo/${HUGO_BINARY}.tar.gz \
&& tar xzf /usr/local/hugo/${HUGO_BINARY}.tar.gz -C /usr/local/hugo/ \
&& rm /usr/local/hugo/${HUGO_BINARY}.tar.gz \
&& rm -rf /tmp/* /var/cache/apk/* In my Dockerfile for my personal hugo based blog I use multi stage builds feature in docker to generate static HTML using hugo. As you can see from below snipped that I'm using the "hugo-docker" image I created as builder image and create a directory named "blog" under /var/www/ and copy all files into that directory.
FROM rprakashg/hugo-docker as builder
RUN mkdir -p /var/www/blog
COPY . /var/www/blogNext, we switch the working directory to "/var/www/blog" and run hugo command as shown in below snippet to generate the static HTML
WORKDIR /var/www/blog
RUN hugoFinal image is built using the official nginx image from docker hub and we copy all generated HTML content from "public" folder into "/usr/share/nginx/html"
FROM nginx
COPY --from=builder /var/www/blog/public/ /usr/share/nginx/htmlYou can see the full docker file here
Lastly, I threw together couple of helpful bash scripts that I can use to build and run the container so I don't have to always remember the docker commands :)
The cool thing about this is I can now run my blog anywhere, I use to host my blog previously in azure with Wordpress and MySQL, by using hugo I freed myself from dependency to web servers, runtimes, databases etc. but was still dependant on AWS S3 to host the generated static HTML content. Even though its pretty minor you are sort of locked into AWS. Docker gives me freedom to run it anywhere and I love it :)
Hope that helps...
Cheers,
Ram
Related Posts
RAM GOPINATHAN
August 12, 2026
Building Kubernetes-Style APIs: A Practical Walkthrough
Kubernetes real innovation is the declarative, self-healing API pattern. This post builds that pattern from scratch: an OpenAPI-first server, a Postgres-backed store instead of etcd, and a clean service/store split that keeps business logic out of the database
RAM GOPINATHAN
February 28, 2026
Automating post install configurations with cloud-init for Red Hat Enterprise Linux deployments on baremetal environments
Stop configuring servers by hand. Here's how cloud-init brings cloud-level automation to your physical infrastructure.
RAM GOPINATHAN
January 22, 2026
PODMAN TIPS: Implementing init container pattern for containers running on PODMAN
If you’ve worked with Kubernetes, you’re probably familiar with init containers—containers that run before the main application and are typically used for setup or initialization tasks. In this post,…