# Do you see anything wrong with this Dockerfile for GitHub Pages?

**URL:** https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061
**Category:** Help
**Created:** [February 28, 2023, 4:41pm UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061 "2023-02-28T16:41:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BillRaymond](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/billraymond/32/5963_2.png) [@BillRaymond](https://talk.jekyllrb.com/u/BillRaymond)
#### Post date: [February 28, 2023, 4:41pm UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061/1 "2023-02-28T16:41:44Z")

</div>

I built a Dockerfile designed to work specifically with the GitHub Pages variant of Jekyll. I am creating a video that shows how to use it. Before I go too far, I would like to know if you have any issues with this implementation?

@ashmaroli has seen a variant of this and suggested Bison likely is not needed, although I do not understand what it does, it was just recommended on several sites I visited, so I left it for no reason other than it seems to be working 🙂

```auto
Dockerfile

```

```auto
FROM ubuntu:22.04

RUN echo "#################################################"
RUN echo "Get the latest APT packages"
RUN echo "apt-get update"
RUN apt-get update

RUN echo "#################################################"
RUN echo "Install prerequisites"
RUN echo "Partially based on https://gist.github.com/jhonnymoreira/777555ea809fd2f7c2ddf71540090526"
RUN apt-get -y install \
    git \
    curl \
    autoconf \
    bison \
    build-essential \
    libssl-dev \
    libyaml-dev \
    libreadline6-dev \
    zlib1g-dev \
    libncurses5-dev \
    libffi-dev \
    libgdbm6 \
    libgdbm-dev \
    libdb-dev \
    apt-utils
    
ENV RBENV_ROOT /usr/local/src/rbenv
ENV RUBY_VERSION 3.1.2
ENV PATH ${RBENV_ROOT}/bin:${RBENV_ROOT}/shims:$PATH

RUN echo "#################################################"
RUN echo "Install rbenv to manage Ruby versions"
RUN git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} \
  && git clone https://github.com/rbenv/ruby-build.git \
    ${RBENV_ROOT}/plugins/ruby-build \
  && ${RBENV_ROOT}/plugins/ruby-build/install.sh \
  && echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh

RUN echo "#################################################"
RUN echo "Install ruby and set the global version"
RUN rbenv install ${RUBY_VERSION} \
  && rbenv global ${RUBY_VERSION}

RUN echo "#################################################"
RUN echo "Install Jekyll 3.9.x and include GitHub Pages as a dependency"
RUN gem install jekyll -v '~>3.9.0'
RUN gem install bundler
RUN bundle init
RUN bundle add "github-pages" --version "228" --group "jekyll_plugins"
RUN bundle add webrick

```

Basically, I am performing the following steps:

1. Use Ubuntu 22.04 and install [what I assume to be the correct] dependencies for Ubuntu, Ruby, and Jekyll
2. Install Jekyll 3.9.x (the current version of Jekyll supported on GitHub Pages… as of this writing, it is 3.9.3)
3. Initialize a bundle with GitHub Pages version 228 and put it in a `jekyll_plugins` group, as per [this GitHub documentation](https://pages.github.com/versions/) and [this GitHub documentation](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll#creating-your-site)
4. Add `webrick`, as I believe this is an issue with 3.9.x.

After I build a Docker container using the Dockerfile, I would go into the folder where the Dockerfile already exists, and type the following in a terminal window:

```auto
bundle exec jekyll new . --force
RUN bundle install
RUN bundle update

```

If you have any thoughts, I would appreciate hearing them.

As a reminder, I have not encountered issues, so this is more of a verification question.

Thanks!

---

<div class="post-metadata">

### Author: ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)
#### Post date: [March 1, 2023, 1:12am UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061/2 "2023-03-01T01:12:13Z")

</div>

> [@BillRaymond](#):
>
> After I build a Docker container using the Dockerfile, I would go into the folder where the Dockerfile already exists, and type the following in a terminal window:
> 
> ```auto
> bundle exec jekyll new . --force
> RUN bundle install
> RUN bundle update
> 
> ```

Maybe a typo: the `RUN` in `RUN bundle install`, etc. will produce an error in a terminal-window/shell. Maybe you meant those lines to be added to the `Dockerfile`? Or remove `RUN`?

Also, should those command be run in the Container’s shell? Or local shell (where the `Dockerfile` lives)?

About `bundle install`, my understanding is that Github-Pages ignores `Gemfile`. I.e. any `Gemfile` in a Github-Pages repo are purely for local development, and are ignore when Github-Pages builds the site. Whether this is an issue depends on what level of Github-Pages fidelity you’re aiming for. For example, if you want errors for unapproved plugins, then I think you’d need to ignore the user’s `Gemfile`. Ref: [https://stackoverflow.com/questions/56261127/is-the-gemfile-lock-file-needed-in-a-jekyll-site-hosted-with-github-pages](https://stackoverflow.com/questions/56261127/is-the-gemfile-lock-file-needed-in-a-jekyll-site-hosted-with-github-pages)

---

<div class="post-metadata">

### Author: ![BillRaymond](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/billraymond/32/5963_2.png) [@BillRaymond](https://talk.jekyllrb.com/u/BillRaymond)
#### Post date: [March 1, 2023, 2:34am UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061/3 "2023-03-01T02:34:06Z")

</div>

@chuckhoupt Good catch re: the RUN commands. I was testing today and found the same issue. They should be a post-run command and not included in the Docker image.

Regarding the Gemfile and Gemfile.lock, I understand they are not required, but when developing locally they can help you avoid installing gems that GitHub Pages does not support (based on my lackluster memory since I mostly use Jekyll 4.x 🙂 ). I think I will leave that in because this training aims to set up a local Docker dev environment compatible with GitHub Pages-flavored Jekyll.

Thanks for the catches!

---

<div class="post-metadata">

### Author: ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)
#### Post date: [March 1, 2023, 11:16am UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061/4 "2023-03-01T11:16:38Z")

</div>

Hello,  
Not sure if I said this prior thread(s), but I see some scope for edits.

Towards the end after `RUN gem install bundler`, I don’t see the point of initializing a Gemfile and adding gems to it when you scaffold a Jekyll site in a subsequent step.  
Running `jekyll new <path>` creates a new Gemfile and immediately runs `bundle install` using that Gemfile. You need to pass the flag `--skip-bundle` to avoid this. Once the scaffolding completes, you may add needed additional gems like `github-pages` and `webrick`. To my knowledge, `bundle add <gem_name>` includes `bundle install`. So there is no need for a subsequent explicit `bundle install` and `bundle update` incantations.

In summary, my set up process would be (example shell script):

```sh
gem install jekyll -v '~> 3.9'
gem install bundler

jekyll new my_site --skip-bundle --force
cd my_site
bundle add "github-pages" --group "jekyll_plugins"
bundle add webrick

```

---

<div class="post-metadata">

### Author: ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)
#### Post date: [March 1, 2023, 4:13pm UTC](https://talk.jekyllrb.com/t/do-you-see-anything-wrong-with-this-dockerfile-for-github-pages/8061/5 "2023-03-01T16:13:35Z")

</div>

Ah, I love a minimization challenge 😀. I setup a simple [Github-Pages test repo](https://github.com/chuckhoupt/pagestest), and then tried to generate the same site with Docker. Here’s the shortest steps so far:

Run Ruby in Docker:

```plaintext
docker run -it --rm ruby bash

```

In the container shell, run the following commands:

```bash
# Setup basic one-page Markdown site in home dir
cd ~ ; echo hello > index.md

# Setup for Github-Pages
bundle init
bundle add "github-pages" --group "jekyll_plugins"

# Build it
PAGES_REPO_NWO=chuckhoupt/pagestest jekyll build

```

The resulting `_site/index.html` is near-identical to the Github-Pages generated version at [https://chuckhoupt.github.io/pagestest/index.html](https://chuckhoupt.github.io/pagestest/index.html)
