Build Stages: Sharing a Docker image

This example has 2 build stages:

  • One job builds and pushes a Docker image
  • Two jobs that pull and test the image

Here’s what the .travis.yml config could look like:

sudo: true
dist: trusty

    - stage: build docker image
      - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
      - docker build -t travis-ci-build-stages-demo .
      - docker images
      - docker tag travis-ci-build-stages-demo $DOCKER_USERNAME/travis-ci-build-stages-demo
      - docker push $DOCKER_USERNAME/travis-ci-build-stages-demo
    - stage: test
      script: docker run --rm $DOCKER_USERNAME/travis-ci-build-stages-demo cat hello.txt
    - script: docker run --rm $DOCKER_USERNAME/travis-ci-build-stages-demo cat hello.txt

This is how the build matrix might look:


You can find the code for this example on our demo repository: