This blog is hosted on Github Pages. It allows me to just write content and not worry about server infrastructure or blog engine upgrades. Github Pages uses Jekyll behind the scenes, which allows users to just write Markdown posts.
Jekyll and Windows
To be able to preview your Jekyll site, you’ll want to run it locally. In the docs we find the following:
While Windows is not officially supported, it is possible to get it running on Windows. Special instructions can be found on our Windows-specific docs page.
The page then goes on on how to install Ruby on Windows before installing Jekyll. Until recently, that’s what I did, however it’s a bit of a pain. Preferably, I wouldn’t want to install Ruby just to preview my blog entries.
This sounds like a good use case for using container technology. With the recent release of Docker For Windows, setting up Docker on Windows is such a breeze. It uses Hyper-V under the covers, sets up port-forwarding so you can use localhost to access services hosted on Docker, and a bunch of other magic to make it all work seamlesslsy.
If you’ve used Docker before, but found it a bit of a pain to set up (especially on Windows), I highly encourage you to try it out again.
Running Jekyll in Docker
If you don’t have a Jekyll site/blog and want to follow along, feel free to clone my blog.
git clone https://github.com/samneirinck/samneirinck.github.io
Jekyll has an official image on Docker Hub. This makes it even more easy to use. All that’s needed is running the following command:
docker run --rm --volume=/c/path/to/blog:/srv/jekyll -it -p 4000:4000 jekyll/jekyll:pages
Sure enough, browsing to http://localhost:4000 lets us visit the Jekyll site locally.
Creating a docker-compose file
This is great, but the command is a bit long to remember. Why not create a docker-compose file so we can reduce it to just one command.
In the root folder of the site, create a docker-compose.yml file with the following contents:
version: '2' services: web: image: jekyll/jekyll:pages command: jekyll s --force_polling --drafts ports: - "4000:4000" volumes: - .:/srv/jekyll
We’re using the
--force_polling option to make jekyll regenerate the site whenever there are changes in the markdown files, productivity success.
Once this file is set up, run the following command:
Browsing to http://localhost:4000 shows our blog again, and we can now edit our blog drafts, and preview them directly in the browser.
Using Docker For Windows it’s now easier than ever to spin up your Jekyll site on Windows and do your modifications. I can now work on my blog from any machine, with or without internet connection, and have an exact preview on what it will look like if I publish a post.