This blog is created in Jekyll, and hosted in Github Pages. The setup is as simple as possible and is limited to the versions of the plugins that are included in the github-pages gem.

When the files are commited to my github repo the site is automatically built and deployed to Github Pages.

I wanted to test the site locally, but I didn’t want to install all the prerequisited for Jekyll, like Ruby. So instead I used Docker to create, build and test the site using the jekyll/jekyll image.

Below are the steps involved when creating a site in Jekyll running in a container and test locally.

Prerequisites

  • First get Docker up and running, and download the jekyll image.
  • Create a new repo in Github that will contain your Github Pages site, and clone it locally.
  • Navigate to the folder where the repo is, and run this command to create a new Jekyll site in this folder.
docker run --rm --volume="$(PWD):/srv/jekyll" -it jekyll/jekyll sh -c "chown -R jekyll /usr/gem/ && jekyll new ."
  • Create a Gemfile in the repo with the following content:
source "https://rubygems.org"

gem "github-pages", "~> 232", group: :jekyll_plugins
gem "kramdown-parser-gfm" 
  • Update the _config.yml file and add the following:
theme: minima

plugins:
  - jekyll-sitemap

This explicitly tells Jekyll to use the jekyll-sitemap plugin, which for some reason is not enabled by default (like most other plugins that comes with the github-pages gem is).

Serving the site locally

You can now use the following command to build and serve the site locally on http://localhost:4000.

docker run --rm --volume="$(PWD):/srv/jekyll" --publish 4000:4000 -it jekyll/jekyll sh -c "chown -R jekyll /usr/gem/ && bundle install && bundle exec jekyll serve --watch --force_polling --host=0.0.0.0"
  • --host=0.0.0.0 - needed, otherwise it will serve at 127.0.0.1, which is not available outside of the container.
  • --force_polling - needed when --watch is enabled, because for some reason the file change events made locally are not propagated to the container. This allows us to automatically rebuild the site if we make changes.