Following up on my last port, I’m going to extend the setup and, instead of letting Jekyll serve the static site, I will let nginx do that. This time, Jekyll will only create the static site.
I’m doing this similarly to how James Turnbull does in his book The Docker Book. He created one image for building the static HTML pages with Jekyll and another image for serving them with Apache.
I just found a useful comparison of Apache and Nginx: Apache vs Nginx: Practical Considerations.
My reason for using nginx is simpler: I ‘ve used it before but had forgotten much. 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 of how to build a deployment pipeline with Docker: have one or more containers create build artifacts and then have containers deliver or serve the final product. In between there are so-called Docker volumes— 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 the official nginx image:
docker pull nginx
We have two options for starting 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 happens is that the second container uses the data from the first container. So-called Docker volumes are used to keep the data accessible even without a running container.
As far as I know, there are two main approaches to using Docker volumes. The articles below should help you decide how to persist data with Docker:
- How to deal with persistent storage (e.g. databases) in docker
- Why Docker Data Containers are Good
- Advanced Docker Volumes
My quick conclusion after reading them? If portability of your data is required, go for volume containers.
Done for today!