---
title: Deploying Jekyll using Docker
url: https://blog.octoperf.com/deploying-jekyll-using-docker/
date: '2016-01-15'
authors:
- gpereira
categories:
- DevOps
tags:
- Amazon
- Jekyll
- Docker
- Cloud
- Jenkins
description: Using Docker to build and deploy static websites on Amazon S3.
---

# Deploying Jekyll using Docker

To [build the website of Octoperf](https://blog.octoperf.com/hosting-jekyll-on-amazon-web-services/), our load testing tool, we use Jekyll. I also use it for this website.

It's great to **generate static content**, hosted on Amazon S3 like OctoPerf or on Github for this blog.
But we had trouble upgrading jekyll to version 3 on our build server. We use plugin that are not yet available for this version. So we had to revert back to 2.5.

## Docker to the rescue

The whole process took us time. So I decided to **use Docker to build, optimize and deploy our website**.
Now all we need is Docker installed on our build server and available in Jenkins, the Continuous Integration tool we use.

I wrote a simple script that:

* Builds the website using [jekyll/jekyll docker image](https://github.com/jekyll/docker),
* Optimizes PNG using [docker-optipng image](https://hub.docker.com/r/buffcode/docker-optipng/),
* and uploads it to [Amazon S3](https://hub.docker.com/r/attensee/s3_website/).


```sh
#!/bin/sh

WORKSPACE=${1:-`pwd`}

docker run --rm -i -p $(docker-machine ip `docker-machine active`):4000:4000 -v=$WORKSPACE:/srv/jekyll jekyll/jekyll:2.5.3 /bin/sh -c "jekyll build"
cd $WORKSPACE/_site
find . -name "*.png" | xargs docker run --rm -v=$WORKSPACE/_site:/source buffcode/docker-optipng -o4
docker run --rm -i -v=$WORKSPACE/_site:/website -v=$WORKSPACE/conf:/config attensee/s3_website push --config-dir /config --site /website
```


Using Docker, **we don't need to maintain installations of ruby, rvm, gems, jekyll and so on**. The build process may take a bit longer, but that's not a big issue.
I even started to use this solution on my laptop, to build the website locally.
