If you are using Docker with Travis CI and you are not using some Docker registry to hold your pre-built images you will have to build the images on Travis with every build. Even for simple application stacks this can be a slow and expensive process. Ideally you want to move towards publishing your images to a registry.

A registry holds the images at different versions so they can be pulled down quickly, easily and contain an exact snapshot of what your application needs for that tag. A registry is similar to a Git repository where you have commits (this would be the image versions) and tags pointed to specific commits. The latest tag is kind of like the master branch.

There are several good Docker registries, one of which is Amazon EC2 Container Service, or ECS for short.

We chose to use ECS because we use many other AWS products, so it just made sense. However, your needs may be different. This article is specially about how to use ECS with Travis.

Here is the important snippet for your Travis configuration:

before_install:
# Update docker-engine.
- sudo apt-get update
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-engine

# Travis uses an older docker-composer (v1.4.2), we need to update it.
- docker-compose --version
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.8.0-rc2/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin

# Do AWS login for ECR.
- pip install --user awscli
- export PATH=$PATH:$HOME/.local/bin
- export AWS_ACCESS_KEY_ID=
- export AWS_SECRET_ACCESS_KEY=
- $(aws ecr get-login --region us-west-2)

# Compose docker containers.
- docker-compose --version
- docker-compose up -d
- docker images
- docker ps

The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY need to be filled in if they have not been set any other way (such as using encrypted environment variables). You will also may need to change the --region. It is best to create new keys just for Travis in case they need to be changed in the future.