<commit_before>Use the Docker plugin to build and push Docker images to a public or even a
private registry.

## Config

The following parameters are used to configure the plugin:

* **registry** - authenticates to this registry
* **username** - authenticates with this username
* **password** - authenticates with this password
* **email** - authenticates with this email
* **repo** - repository name for the image
* **tag**, **tags** - repository tags for the image
* **dockerfile** - dockerfile to be used, defaults to Dockerfile
* **context** - the context path to use, defaults to root of the git repo
* **insecure** - enable insecure communication to this registry
* **mirror** - use a mirror registry instead of pulling images directly from the central Hub
* **bip** - use for pass bridge ip
* **dns** - set custom dns servers for the container
* **storage_driver** - use `aufs`, `devicemapper`, `btrfs` or `overlay` driver
* **storage_path** - location of docker daemon storage on disk
* **build_args** - [build arguments](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg) to pass to `docker build`
* **mtu** - custom [mtu settings](https://docs.docker.com/v1.8/articles/networking/#docker0) when starting the docker daemon

The following secret values can be set to configure the plugin.

* **DOCKER_REGISTRY** - corresponds to **registry**
* **DOCKER_USERNAME** - corresponds to **username**
* **DOCKER_PASSWORD** - corresponds to **password**
* **DOCKER_EMAIL** - corresponds to **email**

It is highly recommended to put the **DOCKER_USERNAME**, **DOCKER_PASSWORD**
and **DOCKER_EMAIL** into secrets so it is not exposed to users. This can be
done using the drone-cli.

```bash
drone secret add --image=plugins/docker \
    octocat/hello-world DOCKER_USERNAME kevinbacon

drone secret add --image=plugins/docker \
    octocat/hello-world DOCKER_PASSWORD <PASSWORD>

drone secret add --image=plugins/docker \
    octocat/hello-world DOCKER_EMAIL <EMAIL>
```

Then sign the YAML file after all secrets are added.

```bash
drone sign octocat/hello-world
```

See [secrets](http://readme.drone.io/0.5/usage/secrets/) for additional
information on secrets

## Examples

Simple publishing of a docker container:

```yaml
pipeline:
  docker:
    image: plugins/docker
    username: kevinbacon
    password: <PASSWORD>
    email: <EMAIL>
    repo: foo/bar
    tag: latest
    dockerfile: Dockerfile
    insecure: false
```

Publish an image with multiple tags:

```yaml
pipeline:
  docker:
    image: plugins/docker
    username: kevinbacon
    password: <PASSWORD>
    email: <EMAIL>
    repo: foo/bar
    tags:
      - latest
      - 1.0.1
      - "1.0"<commit_msg>Update DOCS.md for 0.5 format [ci skip]<commit_after>Use the Docker plugin to build and push Docker images to a public or even a
private registry.

## Config

The following parameters are used to configure the plugin:

* **registry** - authenticates to this registry
* **username** - authenticates with this username
* **password** - authenticates with this password
* **email** - authenticates with this email
* **repo** - repository name for the image
* **tag**, **tags** - repository tags for the image
* **dockerfile** - dockerfile to be used, defaults to Dockerfile
* **context** - the context path to use, defaults to root of the git repo
* **insecure** - enable insecure communication to this registry
* **mirror** - use a mirror registry instead of pulling images directly from the central Hub
* **bip** - use for pass bridge ip
* **dns** - set custom dns servers for the container
* **storage_driver** - use `aufs`, `devicemapper`, `btrfs` or `overlay` driver
* **storage_path** - location of docker daemon storage on disk
* **build_args** - [build arguments](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg) to pass to `docker build`
* **mtu** - custom [mtu settings](https://docs.docker.com/v1.8/articles/networking/#docker0) when starting the docker daemon

---
date: 2016-01-01T00:00:00+00:00
title: Docker
author: drone-plugins
tags: [ publish, docker ]
repo: drone-plugins/drone-docker
image: plugins/drone
---

The Docker plugin can be used to build and publish images to the Docker registry. The following pipeline configuration uses the Docker plugin to build and publish Docker images:

```yaml
pipeline:
  docker:
    image: plugins/docker
    username: kevinbacon
    password: <PASSWORD>
    email: <EMAIL>
    repo: foo/bar
    tags: latest
```

Example configuration using multiple tags:

```diff
pipeline:
  docker:
    image: plugins/docker
    repo: foo/bar
-   tags: latest
+   tags:
+     - latest
+     - 1.0.1
+     - 1.0
```

Example configuration using build arguments:

```diff
publish:
  docker:
    image: plugins/docker
    repo: foo/bar
+   build_args:
+     - HTTP_PROXY=http://yourproxy.com
```

Example configuration using alternate Dockerfile:

```diff
publish:
  docker:
    image: plugins/docker
    repo: foo/bar
-   dockerfile: Dockerfile
+   dockerfile: path/to/Dockerfile
```

Example configuration using a custom registry:

```diff
pipeline:
  docker:
    image: plugins/docker
-   repo: foo/bar
+   repo: index.company.com/foo/bar
+   registry: index.company.com
```

Example configuration using inline credentials:

```diff
pipeline:
  docker:
    image: plugins/docker
+   username: kevinbacon
+   password: <PASSWORD>
    repo: foo/bar
```

# Secrets

The Docker plugin supports reading credentials from the Drone secret store. This is strongly recommended instead of storing credentials in the pipeline configuration in plain text.

```diff
pipeline:
  docker:
    image: plugins/docker
-   username: kevinbacon
-   password: <PASSWORD>
    repo: foo/bar
```

Use the command line utility to add secrets to the store:

```nohighlight
drone secret add --image=plugins/docker \
    octocat/hello-world DOCKER_USERNAME kevinbacon

drone secret add --image=plugins/docker \
    octocat/hello-world DOCKER_PASSWORD <PASSWORD>
```

Don't forget to sign the Yaml after making changes:

```nohighlight
drone sign octocat/hello-world
```

# Secret Reference

DOCKER_USERNAME
: docker registry username

DOCKER_PASSWORD
: docker registry password

DOCKER_EMAIL
: docker registry email

# Parameter Reference

registry
: authenticates to this registry

username
: authenticates with this username

password
: authenticates with this password

email
: authenticates with this email

repo
: repository name for the image

tags
: repository tag for the image

dockerfile
: dockerfile to be used, defaults to Dockerfile

auth
: auth token for the registry

context
: the context path to use, defaults to root of the git repo

force_tag=false
: replace existing matched image tags

insecure=false
: enable insecure communication to this registry

mirror
: use a mirror registry instead of pulling images directly from the central Hub

bip=false
: use for pass bridge ip

dns
: set custom dns servers for the container

storage_driver
: supports `aufs`, `overlay` or `vfs` drivers

build_args
: custom arguments passed to docker build

Publish an image with multiple tags:

```yaml
pipeline:
  docker:
    image: plugins/docker
    username: kevinbacon
    password: <PASSWORD>
    email: <EMAIL>
    repo: foo/bar
    tags:
      - latest
      - 1.0.1
      - "1.0"
{'fraction_non_alphanumeric': 0.10192725298588491, 'fraction_numerical': 0.005836047774158523, 'mean_word_length': 3.925802139037433, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6547865', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2160, 'n_words': 819}