Skip to content
Latchkey

How to Build and Push to a Registry in Bitbucket Pipelines

Enable the docker service on a step, then run docker build, login, and push to your registry.

Add services: [docker] so the step has a Docker daemon, then log in with stored credentials and push the built image.

Build, login, and push

The docker service provides the daemon; credentials come from repository variables.

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        name: Build and push
        services:
          - docker
        script:
          - docker build -t myrepo/web:${BITBUCKET_COMMIT} .
          - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USER}" --password-stdin
          - docker push myrepo/web:${BITBUCKET_COMMIT}

Notes

  • The docker service is required for any docker command in a step.
  • BITBUCKET_COMMIT gives a unique, traceable image tag per build.
  • Increase memory with size: 2x if large builds hit the default memory limit.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →