A locally built Docker image within a Bitbucket Pipeline

  bitbucket, bitbucket-pipelines, docker

What I need is a way to build a Dockerfile within the repository as an image and use this as the image for the next step(s).

I’ve tried the Bitbucket Pipeline configuration below but in the "Build" step it doesn’t seem to have the image (which was built in the previous step) in its cache.

pipelines:
  branches:
    main:
      - step:
          name: Docker Image(s)
          script:
            - docker build -t foo/bar .docker/composer 
          services:
            - docker
          caches:
            - docker
      - step:
          name: Build
          image: foo/bar
          script:
            - echo "Hello, World"
            - composer --version
          services:
            - docker
          caches:
            - docker

I’ve tried the answer on the StackOverflow question below but the context in that question is pushing the image in the following step. It’s not about using the image which was built for the step itself.

Bitbucket pipeline use locally built image from previous step

Source: Docker Questions

LEAVE A COMMENT