Deploy a Hugo Site to Dokku with Dockerfile
Here is how to deploy a website built with Hugo to a Dokku host with a Dockerfile.
The Dockerfile
The Dockerfile has two stages:
- The build stage
- The serve stage
# syntax=docker/dockerfile:1
########## 1) Build the site with Hugo (extended) ##########
FROM alpine:3.22 AS builder
# Install Hugo (extended) from Alpine edge/community, plus git for themes/submodules
RUN apk add --no-cache \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
hugo \
&& apk add --no-cache git go ca-certificates
# Put site source into the image
WORKDIR /src
COPY . .
# Optional but recommended: fetch modules up front and vendor them
# (works with module imports defined in hugo.toml / config/_default/module.*)
RUN hugo mod vendor
# If your theme is a git submodule, uncomment:
# RUN git submodule update --init --recursive
# If your site uses PostCSS (e.g., Tailwind via postcss):
# RUN apk add --no-cache nodejs npm \
# && npm ci --no-audit --no-fund
# Build the site (outputs to /public by default here)
ENV HUGO_ENV=production
# You can set BASE_URL at build time: --build-arg BASE_URL=https://example.com
ARG BASE_URL=www.paasbox.app
RUN hugo --minify --baseURL="${BASE_URL}" --destination /public
########## 2) Serve the site with Nginx (Alpine) ##########
FROM nginx:alpine AS runner
# Clean default content and copy in the Hugo build
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /public /usr/share/nginx/html
# Optionally add a custom server config:
# COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
# The nginx:alpine image already sets:
# CMD ["nginx", "-g", "daemon off;"]
Save the dockerfile in the root of your repo. This way, Dokku automatically detects that it should build with docker.
Initial Deployment
ssh dokku@paasbox.app apps:create www
git remote add paasbox dokku@paasbox.app:www
git push paasbox main
Activate TLS with Let’s encrypt:
ssh dokku@paasbox.app letsencrypt:set www email mitja@mitjamartini.com
ssh dokku@paasbox.app letsencrypt:enable www
Optionally add a custom domain
ssh dokku@paasbox.app domains:add www paasbox.com
Update the Website
Commit the changes to git, and then push to your dokku host:
git add .
git commit -m "a change message"
git push
git push paasbox main
Redirects
TODO
Why build with a Dockerfile?
For me, the main reason to use Dockerfile deployments is that they also works on ARM64. Herokuish buildpacks don’t support ARM64, and Pack is only an experimental Dokku feature. Besides that, Dockerfiles are more flexible and usable on other platforms, too.