Building my Jekyll blog in Docker using Ubuntu

Revision history
Tags: jekyll docker


I need Python to build my Jekyll site and the official Docker image to build Jekyll sites looks like a mess to me.

Building Jekyll in Docker

The official image uses alpine as base, but I eventually found out I might get less of a headache using ubuntu:20.04 instead. That gives me good support for both Ruby and Python 3.8 without too much hassle.

I’m not going to use the Jekyll HTTP server, but instead copy the site into a slim nginx image using Docker multi-stage builds.

FROM ubuntu:20.10 AS base
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
               ruby-full build-essential zlib1g-dev \
               git python3 \
    && rm -rf /var/lib/apt/lists/* \
    && groupadd -g 1000 jekyll \
    && useradd -mu 1000 -g jekyll jekyll

USER jekyll
WORKDIR /home/jekyll
ENV GEM_HOME=/home/jekyll/gems \
RUN gem install jekyll bundler

ADD Gemfile Gemfile.lock ./
RUN bundle install

ADD --chown=jekyll:jekyll . ./src
WORKDIR /home/jekyll/src
RUN bundle exec jekyll build --destination ../build --trace

FROM nginx:1.19-alpine
COPY --from=base /home/jekyll/build /usr/share/nginx/html
COPY ./.deploy/default.conf /etc/nginx/conf.d/default.conf

This gives for a very small image in the end.

Take a look at the current source of this Dockerfile for updates. It’s the very file that builds this blog.


If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.