Run Docker commands in Bitbucket Pipelines

Bitbucket Pipelines allows you to build a Docker image from a Dockerfile in your repository and to push that to a Docker registry, by running Docker commands within your build pipeline. Dive straight in – the pipeline environment is provided by default and you don't need to customize it!

Enable access to Docker

To enable access to Docker daemon, add the following option to your bitbucket-pipelines.yml

  docker: true

This will:

  • mount the Docker CLI in your build container
  • run and provide your build access to a Docker daemon

You can verify this by running docker version:

    - step:
          - docker version

  docker: true

You can check your bitbucket-pipelines.yml file with our online validator.

Available Docker commands

Inside your Pipelines script, you can run the following Docker commands:

  • docker login
  • docker build
  • docker tag
  • docker pull
  • docker push
  • docker version

See the Docker command line reference for information on how to use these commands. Other commands, such as docker run, are currently forbidden for security reasons on our shared build infrastructure.

Note that if you've been running commands against your own Docker daemon, this new feature doesn't prevent you from continuing to do that.

Authenticate when pushing to a registry

To push images to a registry, you need to use docker login to authenticate prior to calling docker push

For example, add this to your pipeline script:

docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
最終更新日 2017 年 5 月 22 日





Powered by Confluence and Scroll Viewport.