Docker has been the star of the recent times and I have recently been building a lot of Docker images, deploying them to both development and production (luckily yes!).

Travis CI is one of the most popular CI services and I have lately been using it extensively. It is awesome!

Travis CI YAML

Here is a simple .travis.yml to get started with Docker builds on Travis.

sudo: required

  - docker

  # IMPORTANT! Add your docker slug here (commit once)
  - DOCKER_REPO_SLUG=activatedgeek/mariadb

  # build latest image always
  - docker build -t $DOCKER_REPO_SLUG:latest .
  # build the tagged image
  - if [[ $TRAVIS_TAG = $TRAVIS_BRANCH ]]; then docker build -t $DOCKER_REPO_SLUG:$TRAVIS_BRANCH .; else true ; fi

  # IMPORTANT! Add the environment variables in Travis Build Environment (one time!)
  - docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
  # push to latest if master branch
  - if [[ $TRAVIS_BRANCH = master ]]; then docker push $DOCKER_REPO_SLUG:latest; else true; fi
  # push tag as well
  - if [[ $TRAVIS_TAG = $TRAVIS_BRANCH ]]; then docker push $DOCKER_REPO_SLUG:$TRAVIS_TAG; else true ; fi

Here is how the build behaves under different scenarios:


As a reference project, have a look at

The corresponding Travis builds are available publicly at


The implications of above two assumptions are easy to overcome if need be.

Updates and Corrections

If you see mistakes or want to suggest changes, please create issues or revisions against source.