Testing a Jekyll Website with Docker Locally
This blog post is part of a series around building a website with Jekyll for hosting on github pages
This blogpost will explain how docker can be used to locally create and test a Jekyll website.
Preparing a docker image and container
Github pages can only be used with a specific version of Ruby And Jekyll. Define a docker images that uses the Ruby 2.7 alpine image and use apk to install the Jekyll 3.9.3 Gem:
Create a dockerfile:
Build the docker image:
Create the docker container
If docker is running on a windows systems, to make folder mounting work correctly docker must be running in ‘linux containers’ mode, WSL2 needs to be activated and the command shown above is executed from the ubuntu Windows Subsystem for Linux shell.
Launch the container and start an interactive shell
Start the container
Login to the container with an interactive shell
Create a new Jekyll site
Within the shell of the container test if Jekyll 3.9.3 is correctly available
Navigate to the /usr/src folder and create a fresh Jekyll site. Ensure correct ruby gems are installed and unnecessary gems are removed.
A folder mysite is being created with several new files
Start serving the Jekyll site
'--hosts 0.0.0.0' will tell Jekyll to run on all network interfaces.
Check on the host system if the Jekyll website can be reached by browsing to http://localhost:8080
Modifying content
After creation of a new Jekyll site an example post is created in the _posts folder. To create a new post just copy the existing post and modify the name and content.
Whenever a change is made to any of the files jekyll needs to regenerate the html content. Execute the jekyll build command from within the container. This can be achieved by running a second shell in the docker container.
Publishing to github pages
Next post will talk about how to publish a jekyll page on github pages