Skip to content

Instantly share code, notes, and snippets.

@pbendersky
Last active April 14, 2020 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbendersky/ad26b8ac8e050936b54831fb530f731d to your computer and use it in GitHub Desktop.
Save pbendersky/ad26b8ac8e050936b54831fb530f731d to your computer and use it in GitHub Desktop.
Brief tutorial on how to create a Jekyll based blog on GitHub Pages using Docker

Requirements

  • A running Docker installation.

Create your blog

We'll be using the github-pages gem and the Jekyll Docker image.

The last version of the pages-gem (204) uses Jekyll 3.8.5, so we'll start with that Docker image as a base.

  1. Create an empty folder on your disk, where you'll host your blog. We'll push it to GitHub later.
  2. Within that folder, run: docker run --rm --volume="$PWD:/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" -it jekyll/jekyll:3.8.5 jekyll new . --force This will pull the Jekyll image, and run jekyll new to create a new Jekyll site. We are mounting the local folder vendor/bundle so we can cache the gem and they are not downloaded everytime we run a Jekyll command.
  3. Edit the Gemfile and comment the line that reads gem "jekyll", "~> 3.8.5", and uncomment the line that says gem "github-pages", group: :jekyll_plugins.
    1. Exit vi (out of scope for this tutorial)
  4. Run bundle update within the Docker container by doing: docker run --rm --volume="$PWD:/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" -it jekyll/jekyll:3.8.5 bundle update
  5. Check that your newly created blog is working by running: docker run --rm --publish 4000:4000 --volume="$PWD:/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" -it jekyll/jekyll:3.8.5 jekyll serve and opening http://localhost:4000

If the site works, you are ready to push it to you GitHub pages repository.

  1. Create your GitHub personal pages repository. The name of the repository is based on your username. The repo should be named username.github.io.
  2. On the blog folder, run the usual git commands to make a repo and push it:
    1. git init
    2. git add * (there will be a .gitignore created for you that excludes the generated pages. Keep it).
    3. git add .gitignore
    4. git commit -m "Initial commit"
    5. Add the origin repository git remote add origin git@github.com:username/username.github.io.git
    6. Push git push -u origin master
  3. Check you new blog at https://username.github.io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment