Run Jekyll in Docker
Yes, Jekyll server in Docker on a Mac!!!
Jekyll was not easy with my mac’s system Ruby. So, I was sure that somebody would have definitely faced this issue. So, I got this great solution from Jordon Bedwell. Also, you can refer to another solution from great Docker Captain Bret Fisher as well.
Let’s do it - So, Docker!
First, let’s have the Docker installed and ready.
Docker can be easily installed by downloading and installing Docker Desktop application.
Jekyll Local Dev Server (image)
Now we need to download the readymade Jekyll local development server image from docker hub. You can do it by following command
$ docker pull jekyll/jekyll
This will download the STANDARD
image set with latest version. There is a BUILDER
(with build tools) and MINIMAL
version as well. Let us go with the standard package here.
Document says
The standard images (jekyll/jekyll) include a default set of “dev” packages, along with Node.js, and other stuff that makes Jekyll easy. It also includes a bunch of default gems that the community wishes us to maintain on the image.
Run our project in Docker
For local development, Jekyll can be run in server mode inside the container. It will watch for changes, rebuild the site, and provide access through its included web server. You can then check the results of changes by reloading http://localhost:4000/ in a browser.
$ docker run --rm -it --volume="$PWD:/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" -p 4000:4000 jekyll/jekyll:latest jekyll serve
Serving the site on another port for multiple local dev sessions
By default, all Jekyll server runs on port 4000, unless specified otherwise in _config.yml If you want to serve multiple local servers at same time, you need to change the port configuration as follows.
In _config.yml, at root level, add/change following line to any value you want.
...
port 4001
...
Also, update your docker command above with change in port option (-p) as below
... -p 4001:4001 ...
Awesome!