This article assume you already have a Jekyll installation.

If you don’t please visit Jekyllrb, install and deploy one.

If you need to install read my article Kickstart with Docker and docker-compose

In your home folder?

touch docker-compose.yml

Then paste the following piece of code.


version: '3'

services:
  jekyll:
    image: jekyll/jekyll:latest
    command: jekyll serve --watch --force_polling --verbose
    ports:
      - 4000:4000
    volumes:
      - .:/srv/jekyll

This defines one service called jekyll which uses the Jekyll docker image.

There is a command that automatically trigger Jekyll

The service maps from local port 4000 to container port 4000

It maps from current local folder (.) to container working folder /srv/jekyll.

Enter Linux commands that are executed within the docker container.

If you need to get inside the container run docker-compose run jekyll /bin/bash from the command line. This will download the Jekyll docker image, start the container and tunnel the Linux bash of the container to the command line. If is already downloaded type docker-compose exec jekyll /bin/bash

Notice that the docker-container folder is mapped to our local folder via the volumes option in the docker-compose.yml.

Once jekyll new . --force is finished all necessary Jekyll files for a new blog have been added to the folder. Not only in the Linux container but also in our host Windows folder.

Now the homepage can be served. Serve the homepage

Just run docker-compose up from the command line. That will start the docker-container and run Jekyll. Folders and ports are mapped and the homepage can be browsed under http://localhost:4000/.

If you need a good quick free ide, install it and run it:

sudo apt install sublime-text
subl .

How to get started the containers

docker-compose up -d

How to stop it: docker-compose down

Inspect containers docker ps

Now, I have a jekyll website on the server named steve

$ cat /etc/hosts
114.220.142.47 steve

On the server I created a user called git to be used generical for my jekyll websites.

git clone git@steve:~/spokane.git

Now move docker-compose.yml to spokane folder.

$ mv ./docker-compose.yml spokane

Now on the remote you’ll have the steve server as origin:

git remote -v

Do check localhost:4000m where you’ll have your site running. If is not then make sure your containerization has started with the command docker-compose up -d

Do changes then push them to the server

git add . && git commit -m "docker-compose & stuff"
git push origin master

Note, this command will also lunch website making use of bundle (if you have bundle installed) docker-compose exec jekyll bundle exec jekyll serve

Kickstart a brand new jekyll site

If you don’t have a jekyll site yet run (–force is needed because Jekyll prefers empty folders, but we do already have the docker-compose.yml file in the folder.)

jekyll new . --force in the bash to setup a new homepage. 

A good practice for handling a custom local config


version: '3'

services:
  jekyll:
    image: jekyll/jekyll:latest
    command: jekyll serve --watch --force_polling --verbose --config _config.yml _config_dev.yml
    ports:
      - 4000:4000
    volumes:
      - .:/srv/jekyll

Where in _config_dev.yml you overwrite critical values such us:

baseurl: ''
url: /
google_analytics: #UA-68409070-1
disqus_user: your-user

Debugging

If you for whatever reason the site does not regenerate enter the container and run serve with -w option:

docker-compose exec jekyll bash
bash# jekyll serve -w

You’ll see probably the error that made the generator stuck, as in my case:

/usr/gem/gems/jekyll-sass-converter-2.1.0/lib/jekyll/converters/scss.rb:190:in `rescue in convert': Error: property "grid-row-end" must be followed by a ':' (Jekyll::Converters::Scss::SyntaxError)
        on line 144:3 of _sass/_experimental.scss
        from line 148:1 of main.scss
>>   grid-row-end span 2;

For frontend error you always have the inspect variable:

nil