I have said it before and I am saying it again: great times we are living in. Today’s technology and its resulting tools make it easier than ever to release software to the world.
Docker itself is cool enough, but adding Docker Compose and Docker Machine makes it even better. What I love most is the simplicity of both tools— a simplicity that lets you do great stuff.
Infrastructure as code anyone? There you go…
In this post I’m going to define a very simple deployment process with Docker Compose.
Setting up the Environment
First, we need to install everything: Docker, Docker Machine and Docker Compose
curl https://get.docker.com/builds/Darwin/x86_64/docker-latest > /usr/local/bin/docker
chmod +x /usr/local/bin/docker
docker -v
curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_darwin-amd64 > /usr/local/bin/docker-machine
chmod +x /usr/local/bin/docker-machine
docker-machine -v
curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -v
We are all set to create our Docker host with Docker Machine:
docker-machine create --driver virtualbox local-blog-host
Finally, we need to tell Docker to use our new host:
eval "$(docker-machine env local-blog-host)"
Firing it up
Our deployment consists of several steps:
- Downloading a Jekyll repository from GitHub.
- Building the HTML from the source Markdown.
- Storing the HTML in the volume of our Nginx container.
- Serving the HTML with Nginx.
First we add a docker-compose.yml where we specify our services:
{% gist 0be78ee97c9d05f7ccae docker-compose.yml %}
We are also reusing the Dockerfile from last time:
{% gist 0be78ee97c9d05f7ccae Dockerfile %}
We build the containers and start them with the following command:
docker-compose up -d
Now test it at localhost:8080 in your browser.
Let’s assume someone changed the Markdown files of our Jekyll blog and we need to update everything.
docker-compose build --no-cache jekyllbuild
docker-compose run jekyllbuild
Check localhost:8080 to verify it worked.
Conclusion
That’s all? Yep! What’s next?
This is just a very basic example of what can be done. It should illustrate that we can also use Docker to encapsulate build steps. As always, there is lots of room for optimization depending on specific usage scenarios.
We can also use this example to extend our deployment process and use a cloud-based solution for building and serving the blog.
Done for today!