Skip to content

Instantly share code, notes, and snippets.

@santoso-wijaya
Created February 1, 2024 04:25
Show Gist options
  • Save santoso-wijaya/bfd10ec29deb3a7fd2e69c854af72bfb to your computer and use it in GitHub Desktop.
Save santoso-wijaya/bfd10ec29deb3a7fd2e69c854af72bfb to your computer and use it in GitHub Desktop.
Jekyll on RVM-installed Ruby

This Docker image installs RVM and then has it install Ruby before installing the Jekyll gem.

Building a container

$ docker build -t jekyll .

Listing RVM-managed Rubies

$ docker run --rm --it jekyll "rvm list"

Running Jekyll commands

$ docker run --rm --it jekyll "jekyll help"

Running Jekyll commands that touch files

To do this, you'll need to map a host directory path to a mounted path /vol in the container. For example:

% docker run --rm -it --volume $HOME/site:/vol jekyll "jekyll new hello"
Running bundle install in /vol/hello...
  Bundler: Fetching gem metadata from https://rubygems.org/............
  Bundler: Resolving dependencies...
  Bundler: Fetching rexml 3.2.6
  Bundler: Installing rexml 3.2.6
  Bundler: Fetching jekyll-feed 0.17.0
  Bundler: Fetching jekyll-seo-tag 2.8.0
  Bundler: Installing jekyll-feed 0.17.0
  Bundler: Installing jekyll-seo-tag 2.8.0
  Bundler: Fetching minima 2.5.1
  Bundler: Installing minima 2.5.1
  Bundler: Bundle complete! 7 Gemfile dependencies, 33 gems now installed.
  Bundler: Use `bundle info [gemname]` to see where a bundled gem is installed.Don't run Bundler as root. Installing your bundle as root will break this
  Bundler: application for all non-root users on this machine.
New jekyll site installed in /vol/hello.
% ls $HOME/site
hello
# syntax=docker/dockerfile:1.4
FROM ubuntu:22.04
LABEL org.opencontainers.image.authors="Santoso Wijaya <code@swijaya.com>"
ARG DEBIAN_FRONTEND=noninteractive
RUN <<EOF
apt-get update -q
apt-get install -qy --no-install-recommends \
procps \
curl \
ca-certificates \
gnupg2 \
build-essential \
zlib1g-dev \
wget \
gpg \
xz-utils
apt-get clean
EOF
# Use the bash shell with -l (login) from here on.
# The login behavior is important to trigger RVM's setup scripts.
SHELL [ "/bin/bash", "-l", "-c" ]
# Fetch and install RVM, then use it to install Ruby 3.1.3
RUN <<EOF
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
curl -sSL https://get.rvm.io | bash -s
. /etc/profile.d/rvm.sh && rvm install 3.1.3
EOF
RUN <<EOF
rvm list
ruby -v
gem install jekyll bundler
EOF
# If invoking Jekyll commands that touch files, mount them here.
VOLUME /vol
WORKDIR /vol
ENTRYPOINT ["/bin/bash", "-l", "-c"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment