Skip to content

Jekyll container setup

Introduction

For local development, Jekyll can be run in server mode inside a container. It will watch for changes, rebuild the site, and provide access through its included web server.

Setup

  1. Create the folders needed by the container

    Run the following commands inside your home folder:

    # Open your terminal application
    cd ~
    mkdir -p jekyll/web
    mkdir -p jekyll/cache
    mkdir -p jekyll/build
    cd jekyll
  2. Create the script needed to run the container

    Save the following script as jekyll_run.sh:

    jekyll_run.sh
    # To create this script use your text editor application, for example Nano
    IDu=$(id -u $(logname)) # Saves the logged in user id in the IDu variable
    IDg=$(id -g $(logname)) # Saves the logged in user group in the IDg variable
    docker run -d \
    --hostname=jekyll \
    --name=jekyll \
    -p 0.0.0.0:4000:4000 \
    -v $PWD/web:/srv/jekyll \
    -v $PWD/cache:/usr/local/bundle \
    -v $PWD/build:/srv/jekyll/build \
    -e 'TZ=Europe/Amsterdam' \
    -e JEKYLL_UID=$IDu \
    -e JEKYLL_GID=$IDg \
    jekyll/jekyll \
    jekyll serve --source /srv/jekyll \
    --destination /srv/jekyll/build \
    --disable-disk-cache \
    --watch \
    --force_polling \
    # IMPORTANT: Please read the instructions below
    Instructions:
    • Optional Replace docker with podman if needed
    • Required Replace port number 4000 of 0.0.0.0:4000 (on the left side of :) with a port number that is available if needed
    • Optional Replace for example $PWD/web with the location of your website. Personally I used a fileserver mount which is also shared with a client pc where I can edit my notes
    • Required Replace Europe/Amsterdam with your own timezone
  3. Run the script to create the container

    Run the following command:

    # Open your terminal application
    sudo sh jekyll_run.sh

    The image jekyll/jekyll is automatically pulled and the container is created.

  4. Check the results

    Now you can check if the container is running properly. The log will show that it may take a while for the server to run.

    Make sure you place your Jekyll website in the location which is mapped to /srv/jekyll in the script. You can check the results of changes by reloading http://localhost:4000/ in a browser. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier.

    If changes are made to the source code or to notes (e.g. with [[Obsidian - Setup a Digital Garden with GitHub and Cloudflare Pages|Obsidian]]) Jekyll will automatically detect the changes and generate a new build.

Favorites

Comments

    No comments found for this note.

    Join the discussion for this note on Github. Comments appear on this page instantly.

    Copyright 2021- Fiction Becomes Fact