There are multiple ways you can run a blog, either using WordPress, Squarespace, among others. I’ve decided a long time ago that I’d like to use my website as a experimental platform, though keeping the content consistent. My latest experiment, which is now running for over a year, is to host this as a static site, where my server delivers plain HTML files. I’m using a static site generator called Jekyll to create these HTML files based on templates and content written in Markdown. I’ve written an article in the past about my workflow for writing, this article will provide some technical insight (as I promised a few weeks ago).
Been playing around with @Docker containers so much recently, that I just had to also make it work for my own website. Running a @jekyllrb #container to build my site. Will write it up soon. #developer— Eddo Kloosterman (@eddokloosterman) November 21, 2018
I’ve been playing around with Docker now for a while, and I did like the idea of having all dependencies of an application inside a container so that it doesn’t clutter up your regular system/workstation. This is especially a thing working with Ruby and
gems on macOS. I had to install some dependencies in multiple versions, and that will conflict at some point in time. Docker has provided me a way to keep those dependencies within the container for my website project, not affecting other projects.
There is already a Docker image for Jekyll available, which can be used for these purposes. I added some changes to make it work for my website project, that included resizing images for multiple resolutions (based on a fixed version of Netlify’s
# The base image FROM jekyll/jekyll # Using the _edge_ Alpine repository, as I need a specific version of `ruby-rmagic` RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories # `imagemagick6-dev` needs to stay in it's own command, as it overwrites some dependencies of imagemagick6 RUN apk add --no-cache ruby-rmagick=2.16.0-r2 \ && apk add --no-cache imagemagick6-dev COPY Gemfile . # Run the install of gems within the Docker build process RUN bundle install
Dockerfile with some comments
Together with a
docker-compose.yml file, that you can see below, I’m able to run my site locally and build it. Using the command
docker-compose up I can run it locally (after which it is available via
http://localhost:4000), and with
docker-compose run jekyll jekyll build the site is built for production (without the drafts).
version: '2' services: jekyll: build: ./ command: jekyll serve --drafts --watch --incremental ports: - 4000:4000 volumes: - .:/srv/jekyll
When I’m ready to publish a new article, I build the site with one of the mentioned commands above, and then push the changes to my server with an
rsync shell script.
Concluding; it doesn’t have to be complicated to setup Jekyll on Docker. It saves my macOS workstation from becoming cluttered with Ruby
gems, and if I mess up, I can start over from scratch relatively quickly.
P.S. If you’ve enjoyed this article or found it helpful, please share it, or check out my other articles. I’m on Instagram and Twitter too if you’d like to follow along on my adventures and other writings.