Start working with a Jekyll the easy way with docker. The big advantage of that approach is that you don’t have to setup ruby env and the future upgrades will be easier.

TLDR;

  • Download complete jekyll.sh script curl https://kamilbiela.github.io/assets/files/jekyll.sh --output jekyll.sh
  • Put script inside new empty dir
  • Check contents of file - you wouldn’t trust random file from internet, right? :)
  • Init jekyll site by: jekyll.sh new --force .
  • Serve site by running ‘jekyll.sh serve’

Let’s get started

If you don’t have docker, follow the instructions for your OS on the [docker install page][https://docs.docker.com/get-docker/]

To start, create a directory and cd into it:

mkdir ~/home/mypage
cd ~/home/mypage

This is the directory where Jekyll will install dependencies. We will mount that dir as a volume into a docker container, so we persist dependencies between docker run and save a lot of time.

Now let’s create sh script that will run Jekyll inside a container. Create ./jekyll.sh file and put the following contents:

LOCALPORT=4000
DIRECTORY=$(cd `dirname $0` && pwd)

mkdir -p "$DIRECTORY/vendor/bundle"
docker run --rm -p "$LOCALPORT:4000" -v "$DIRECTORY/vendor/bundle:/usr/local/bundle" -v "$DIRECTORY:/srv/jekyll" -it jekyll/jekyll:latest jekyll "$@"

If you plan to use Jekyll with GitHub pages, change docker tag from jekyll:latest to jekyll:3.8.5 or whatever version GitHub pages runs on

This command will:

  • find a directory of the script (so you don’t have to cd to the dir to run in properly)
  • mount local project directory to docker so Jekyll runs with our disk code
  • create and mount vendor/bundle dir to gem bundler directory to prevent installing them on each run
  • expose port 4000 by LOCALPORT var
  • run any Jekyll subcommand ($@ variable)

Now, to start enjoying working with Jekyll init the page:

jekyll.sh new --force .

Wait for install and then:

jekyll.sh serve

Done!

More to read on other sites: