Skip to main content

A Docker Deployment Pipeline

·2 mins

Following up on my last post, am going to extend the setup and instead letting Jekyll serve the static site, I will let nginx do that. This time, Jekyll will only create the static site.

Am doing this similar like James Turnbull does in his book The Docker Book. He created one image for building the static HTML pages with Jekyll, and one image for serving them with Apache.

Just found a nice article about when to use what comparing Apache and Nginx: Apache vs Nginx: Practical Considerations

The reason why I use nginx is much simpler. I have used it in the past but almost forgot everything. Since I use Apache in my daily work, working with nginx for this post served as a nice refresher.

The whole construct of using two docker containers is a basic example on how to build up a deployment pipeline with docker containers: Having one or more containers create build artifacts and at the end have containers deliver or serve the final product. In between there are so called docker volumes, but more on that at the end of this post.

So, here is the Dockerfile for creating the static site with Jekyll:

{% gist 0be78ee97c9d05f7ccae Dockerfile %}

Build it with docker build —tag="twissmueller/jekyll-blog-to-nginx" --rm=true .

Pull in the official nginx image: docker pull nginx.

We have two options now of how to start the containers.

Option 1:

docker run -v /usr/share/nginx/html --name nginx -p 8080:80 nginx
docker run --rm --volumes-from nginx --name jekyll-blog-to-nginx twissmueller/jekyll-blog-to-nginx:latest

Option 2:

docker run --name jekyll-blog-to-nginx twissmueller/jekyll-blog-to-nginx:latest
docker run --volumes-from jekyll-blog-to-nginx --name nginx -p 80:80 nginx

What will happen now is, that the second container will use the data from the first container. So called Docker volumes are being used to keep the data “somewhere” without having a running container at all times.

As far as I know, there are two ways on how to use Docker volumes. The articles below should help your decision on how to persist data with Docker:

My quick conlusion reading them? In case portability of your data is required, go for volume containers.

Done for today!