2016-12-14 17:29:50 +00:00
---
date: 2016-01-01T00:00:00+00:00
title: Docker
author: drone-plugins
tags: [ publish, docker ]
repo: drone-plugins/drone-docker
image: plugins/drone
---
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
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:
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
```yaml
pipeline:
docker:
image: plugins/docker
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
repo: foo/bar
tags: latest
```
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
Example configuration using multiple tags:
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
```diff
pipeline:
docker:
image: plugins/docker
repo: foo/bar
- tags: latest
+ tags:
+ - latest
+ - 1.0.1
+ - 1.0
```
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
Example configuration using build arguments:
```diff
publish:
docker:
image: plugins/docker
repo: foo/bar
+ build_args:
+ - HTTP_PROXY=http://yourproxy.com
2016-07-22 22:53:09 +00:00
```
2016-12-14 17:29:50 +00:00
Example configuration using alternate Dockerfile:
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
```diff
publish:
docker:
image: plugins/docker
repo: foo/bar
- dockerfile: Dockerfile
+ dockerfile: path/to/Dockerfile
2016-07-22 22:53:09 +00:00
```
2016-12-14 17:29:50 +00:00
Example configuration using a custom registry:
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
```diff
pipeline:
docker:
image: plugins/docker
- repo: foo/bar
+ repo: index.company.com/foo/bar
+ registry: index.company.com
```
2016-07-22 22:53:09 +00:00
2016-12-14 17:29:50 +00:00
Example configuration using inline credentials:
2015-05-15 00:11:26 +00:00
2016-12-14 17:29:50 +00:00
```diff
2016-07-22 22:53:09 +00:00
pipeline:
2015-05-15 00:11:26 +00:00
docker:
2016-08-19 20:07:19 +00:00
image: plugins/docker
2016-12-14 17:29:50 +00:00
+ username: kevinbacon
+ password: pa55word
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: pa55word
2015-05-15 00:11:26 +00:00
repo: foo/bar
2015-09-03 05:14:15 +00:00
```
2016-12-14 17:29:50 +00:00
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 pa55word
```
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
2016-08-27 07:45:08 +00:00
Publish an image with multiple tags:
2015-10-28 01:26:50 +00:00
2015-11-25 14:54:14 +00:00
```yaml
2016-07-22 22:53:09 +00:00
pipeline:
2015-10-28 01:26:50 +00:00
docker:
2016-08-19 20:07:19 +00:00
image: plugins/docker
2015-10-28 01:26:50 +00:00
username: kevinbacon
2015-12-23 04:35:33 +00:00
password: pa55word
2015-10-28 01:26:50 +00:00
email: kevin.bacon@mail.com
repo: foo/bar
2016-07-22 22:53:09 +00:00
tags:
2015-10-28 01:26:50 +00:00
- latest
2016-05-03 23:34:08 +00:00
- 1.0.1
2015-10-28 01:26:50 +00:00
- "1.0"
```
2016-07-22 22:53:09 +00:00
Build an image with additional arguments:
2015-12-24 00:40:30 +00:00
```yaml
2016-07-22 22:53:09 +00:00
pipeline:
2015-12-24 00:40:30 +00:00
docker:
2016-08-19 20:07:19 +00:00
image: plugins/docker
2015-12-24 00:40:30 +00:00
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
repo: foo/bar
build_args:
- HTTP_PROXY=http://yourproxy.com
```
2015-10-28 01:26:50 +00:00
2016-08-27 20:56:27 +00:00
## Using a custom registry
Please note that when using a custom registry (other than DockerHub) you will need to provide the registry URL and you will need to use a fully qualified repository name. For example:
```yaml
pipeline:
docker:
image: plugins/docker
registry: http://registry.company.com
repo: registry.company.com/my/image
```
2016-01-02 17:02:08 +00:00
## Caching
2016-07-22 22:53:09 +00:00
The Drone build environment is, by default, ephemeral meaning that you layers
are not saved between builds. There are two methods for caching your layers.
2016-01-02 17:02:08 +00:00
### Graph directory caching
2016-07-22 22:53:09 +00:00
This is the preferred method when using the `overlay` or `aufs` storage
drivers. Just use Drone's caching feature to backup and restore the directory
`/drone/docker` , as shown in the following example:
2015-11-09 04:44:56 +00:00
2015-11-25 14:54:14 +00:00
```yaml
2016-07-22 22:53:09 +00:00
pipeline:
sftp_cache:
2016-08-19 20:07:19 +00:00
image: plugins/sftp-cache
2016-07-22 22:53:09 +00:00
restore: true
mount: /drone/docker
2015-11-09 04:44:56 +00:00
docker:
2016-08-19 20:07:19 +00:00
image: plugins/docker
2016-05-03 23:34:08 +00:00
storage_path: /drone/docker
2015-11-09 04:44:56 +00:00
username: kevinbacon
2015-12-23 04:35:33 +00:00
password: pa55word
2015-11-09 04:44:56 +00:00
email: kevin.bacon@mail.com
repo: foo/bar
2016-07-22 22:53:09 +00:00
tags:
2015-11-09 04:44:56 +00:00
- latest
- "1.0.1"
2016-07-22 22:53:09 +00:00
sftp_cache:
2016-08-19 20:07:19 +00:00
image: plugins/sftp-cache
2016-07-22 22:53:09 +00:00
rebuild: true
mount: /drone/docker
2015-11-09 04:44:56 +00:00
```
2015-10-28 00:26:08 +00:00
## Troubleshooting
2016-07-22 22:53:09 +00:00
For detailed output you can set the `DOCKER_LAUNCH_DEBUG` environment variable
in your plugin configuration. This starts Docker with verbose logging enabled.
2015-10-28 00:26:08 +00:00
2015-11-25 14:54:14 +00:00
```yaml
2016-07-22 22:53:09 +00:00
pipeline:
2015-10-28 00:26:08 +00:00
docker:
environment:
- DOCKER_LAUNCH_DEBUG=true
```
## Known Issues
2016-07-22 22:53:09 +00:00
There are known issues when attempting to run this plugin on CentOS, RedHat,
and Linux installations that do not have a supported storage driver installed.
You can check by running `docker info | grep 'Storage Driver:'` on your host
machine. If the storage driver is not `aufs` or `overlay` you will need to
re-configure your host machine.
2015-10-28 00:26:08 +00:00
2016-07-22 22:53:09 +00:00
This error occurs when trying to use the default `aufs` storage Driver but aufs
is not installed:
2015-10-28 00:26:08 +00:00
```
level=fatal msg="Error starting daemon: error initializing graphdriver: driver not supported
```
2016-07-22 22:53:09 +00:00
This error occurs when trying to use the `overlay` storage Driver but overlay
is not installed:
2015-10-28 00:26:08 +00:00
```
level=error msg="'overlay' not found as a supported filesystem on this host.
2015-11-18 17:44:27 +00:00
Please ensure kernel is new enough and has overlay support loaded."
2015-10-28 00:26:08 +00:00
level=fatal msg="Error starting daemon: error initializing graphdriver: driver not supported"
```
2016-07-22 22:53:09 +00:00
This error occurs when using CentOS or RedHat which default to the
`devicemapper` storage driver:
2015-10-28 00:26:08 +00:00
```
2015-11-18 17:44:27 +00:00
level=error msg="There are no more loopback devices available."
level=fatal msg="Error starting daemon: error initializing graphdriver: loopback mounting failed"
2015-10-28 00:26:08 +00:00
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
```
2016-07-22 22:53:09 +00:00
The above issue can be resolved by setting `storage_driver: vfs` in the
`.drone.yml` file. This may work, but will have very poor performance as
discussed [here ](https://github.com/rancher/docker-from-scratch/issues/20 ).
2016-02-18 18:03:02 +00:00
2016-07-22 22:53:09 +00:00
This error occurs when using Debian wheezy or jessie and cgroups memory
features are not configured at the kernel level:
2016-02-18 18:03:02 +00:00
```
time="2015-12-17T08:06:57Z" level=debug msg="Mounting none /sys/fs/cgroup/blkio cgroup blkio"
time="2015-12-17T08:06:57Z" level=debug msg="Mounting none /sys/fs/cgroup/perf_event cgroup perf_event"
time="2015-12-17T08:06:57Z" level=debug msg="Mounting none /sys/fs/cgroup/cpuset cgroup cpuset"
time="2015-12-17T08:06:57Z" level=debug msg="Mounting none /sys/fs/cgroup/cpu,cpuacct cgroup cpu,cpuacct"
time="2015-12-17T08:06:57Z" level=debug msg="Creating /sys/fs/cgroup/memory"
time="2015-12-17T08:06:57Z" level=debug msg="Mounting none /sys/fs/cgroup/memory cgroup memory"
time="2015-12-17T08:06:57Z" level=fatal msg="no such file or directory"
```
2016-07-22 22:53:09 +00:00
The above issue can be resolved by editing your `grub.cfg` and adding
`cgroup_enable=memory swapaccount=1` to you kernel image. This change should
look like that afterwards:
2016-02-18 18:03:02 +00:00
```
menuentry 'Debian GNU/Linux, avec Linux 3.16.0-0.bpo.4-amd64' --class debian --class gnu-linux --class gnu --class os {
load_video
insmod gzio
insmod raid
insmod mdraid09
insmod part_msdos
insmod part_msdos
insmod part_msdos
insmod ext2
set root='(mduuid/dab6cffad124a3d7a4d2adc226fd5302)'
search --no-floppy --fs-uuid --set=root a4085974-c507-4993-a9ed-bdc17e375cad
echo 'Chargement de Linux 3.16.0-0.bpo.4-amd64 ...'
linux /boot/vmlinuz-3.16.0-0.bpo.4-amd64 root=/dev/md1 ro cgroup_enable=memory swapaccount=1 quiet
echo 'Chargement du disque mémoire initial ...'
initrd /boot/initrd.img-3.16.0-0.bpo.4-amd64
```