Using docker-compose on Travis CI

Elliot Chance
Aug 27, 2016 · 3 min read
Image for post
Image for post

If you are not familiar with Dockeryou can read about it in my other article. In this article I’m talking specifically about docker-compose; the tool for building multiple containers (as most application stacks will require).

docker-composeis great. It can be used to deploy to your dev machines, your production application and of course your CI. I’m quite fond of Travis CIbecause it has seamless integration with Github, is free (for public repositories) and works very well with any type of project or build process you want to throw at it.

At the time of writing this Travis has most Docker tools preinstalled, but they are at older versions. So you will have to update them as part of the build script — this adds a little bit of time to the build and some time in the future you can remove that code.

I am going to assume you are familiar with the Travis YAML configuration. Here are the bits that matter:

# You may want to update this to whatever the latest version is, or keep it
# the same as your local machines. However, I have only tested it with 1.8.0+.
# There should be a time in the future when this is not necessary - it is
# explained in more detail below.
# update is required to update the repositories to see the new packages for
# Docker.
- sudo apt-get update
# Now we can install the newer docker-engine which is required for the newer
# docker-composer we will install next. The messy options are to force it to
# be non-interactive (normally it asks you a bunch of config questions).
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-engine
# Print out the current docker-compose version. Once this reports 1.6+ then we
# do not need the following steps.
- docker-compose --version
# As of the writing of this script Travis has docker-compose v1.4.2, we need
# to update it to 1.8+. $DOCKER_COMPOSE_VERSION is provide from the `env`
# above.
- sudo rm /usr/local/bin/docker-compose
- curl -L${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# Check that docker-compose is now running the latest version (or at least the
# one we specified). This is not to be confused with the version we printed
# before doing the update.
- docker-compose --version
# Setup your application stack. You may need to tweak these commands if you
# doing out-of-the-ordinary docker-compose builds.
- docker-compose pull
- docker-compose build
- docker-compose start
# You will want this for logging. If one of your containers does not build for
# whatever reason it's best to report that now before your tests start
# otherwise it can be really tricky to debug why tests are failing sometimes.
- docker ps
# This is just our script to setup all the database tables and other fixtures
# we need. You should remove this if it's not necessary or you have other
# scripts handling this.
- docker/web/

Originally published at on August 27, 2016.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store