Bitbucket pipeline use locally built image from previous step

Viewed 3415

If I'd like to build a docker image in one pipeline step, then use it in a following step - how would I do that?

eg

default:
    - step:
        name: Build
        image: 
        script:
          - docker build -t imagename:local .
          - docker images
    - step:
        name: Deploy
        image: 
        script:
          - docker images

In this example, the image shows up in the first step, but not the second

1 Answers

You would use Docker Save/Load in conjunction with bitbucket artifacts.

Example:

- step:
  name: Build docker image
  script:
    - docker build -t "repo/imagename" .
    - docker save --output tmp-image.docker repo/imagename
  artifacts:
    - tmp-image.docker
- step:
  name: Deploy to Test
  deployment: test
  script:
   - docker load --input ./tmp-image.docker
   - docker images

Source: Link

Related