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:
dist: trusty
jobs:
include:
- stage: build docker image
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- 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: