Dockerized Jekyll
In my previous post I told about switching from Fedora to CentOS. Most of the software was pretty easy to set up, and if something was missing, it was quite convenient to just to ./configure; make; make install
. But some things were just not that easy. For example the generation of this web site.
Jekyll is written on Ruby. Ok, so I installed ruby, but the version was too old! So no luck there. I didn’t feel like compiling the Ruby from sources, so I did something else: I created by blogging environment as Docker container.
Idea is this: I maintain the web site repository on the host system, and edit the source files there with Emacs. Then I have the Jekyll dev site running in the container, and when I’m happy with my blog post, I just push the sources from the host system and close down the container.
This is my Dockerfile:
FROM debian
RUN apt-get update && \
apt-get -y install \
ruby \
ruby-dev \
build-essential \
rsync \
python \
ssh \
git \
vim
RUN groupadd jarkko -g 1000
RUN useradd -rm -d /home/jarkko -s /bin/bash -g jarkko -u 1000 jarkko
USER jarkko
WORKDIR /home/jarkko
RUN gem install --user bundle jekyll
RUN echo 'export PATH=/home/jarkko/.gem/ruby/2.5.0/bin:$PATH' \
> /home/jarkko/.bashrc
VOLUME /home/jarkko/.gem
EXPOSE 4000
RUN mkdir website
WORKDIR /home/jarkko/website
I run the container like this:
docker run --rm --name blog -p 4000:4000 \
-v blog_gems:/home/jarkko/.gem \
-v /home/jarkko/dev/bitbucket/website:/home/jarkko/website:Z \
-u jarkko -it debian-blog bash
Some notes:
- There’s a Docker volume for
.gem
, because I don’t want to re-install all the gems every time I start the container - The repository is shared with SELinux flag (
:Z
) because I run the Docker with SELinux - I run
bash
interactively, so I can do things like this:
jarkko@26a82303f5d9:~/website$ bundle exec jekyll serve --host=0.0.0.0
Configuration file: /home/jarkko/website/_config.yml
Source: /home/jarkko/website
Destination: /home/jarkko/website/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 2.687 seconds.
Auto-regeneration: enabled for '/home/jarkko/website'
Server address: http://0.0.0.0:4000/
Server running... press ctrl-c to stop.
Regenerating: 2 file(s) changed at 2019-08-11 15:55:11
_posts/2019-08-11-dockerized-jekyll.org
_posts/.#2019-08-11-dockerized-jekyll.org
...done in 2.404816922 seconds.
Now when I edit my blog post draft in the Emacs, Jekyll dev environment running inside the container works just like it would running on the host.
Sweet!