Bitbucket pipeline use locally built image from previous step
Asked Answered
S

1

21

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

Subtreasury answered 17/11, 2018 at 4:40 Comment(0)
F
25

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

Ferine answered 17/11, 2018 at 4:48 Comment(3)
Say if we would like to make it so that image isnt built everytime from scratch, how would we do it using Bitbucket pipelines? Caches: docker does not seem to work for me, it only caches environment var setup in my Dockerfile but not the apt-get installs or pip installs (which are the ones that take most time)Lamination
@ElgizAbbasov You can build your docker pre-image and push it to docker hub. Each time you download it from the docker hub.Palecek
Instead of pushing every image to Docker Hub, you might consider a cache based on your Dockerfile (i.e. re-build every time the Dockerfile is changed) support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/…Aquarium

© 2022 - 2024 — McMap. All rights reserved.