Skip to main content

Deployment Pipelines with Docker-Compose

·2 mins

I have said it before and I am saying it again: Great times we are living in. Todays technology and its resulting tools make it easier then 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 am 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:

  1. Downloading a Jekyll repository from Github.
  2. Building the HTML from the source markdown.
  3. Storing the HTML in the volume of our Nginx container.
  4. 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 with 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 again on localhost:8080 if that worked out.

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!