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
How to Use a Custom Docker Image in Bitbucket PipelinesRun Bitbucket Pipelines steps inside a custom Docker image, setting image globally or per step and authentica…
How to Use Deployment Environments in Bitbucket PipelinesTrack releases in Bitbucket Pipelines with deployment environments, tagging a step with deployment so the Dep…