Updated 2 years ago by Admin

Pipeline steps are defined as a series of Docker containers. Each step must therefore define the Docker image used to create the container.

1   kind: pipeline
2 type: docker
3 name: default
5 steps:
6 - name: build
7 image: golang:1.12
8 commands:
9 - go build
10 - go test

Drone supports any valid Docker image from any Docker registry:

image: golang
image: golang:1.7
image: library/golang:1.7

Pulling Images

If the image does not exist in the local cache, Drone instructs Docker to pull the image automatically. You will never need to manually pull images.

If the image is tagged with :latest either explicitly or implicitly, Drone attempts to pull the newest version of the image from the remote registry, even if the image exists in the local cache.

To only pull the image if not found in the local cache:

5  steps:
6 - name: build
7 pull: if-not-exists
8 image: golang

To always pull the newest version of the image:

5  steps:
6 - name: build
7 pull: always
8 image: golang:1.12

To never pull the image and always use the image in the local cache:

5  steps:
6 - name: build
7 pull: never
8 image: golang:1.12

Pulling Private Images

If the image is private you need to provide Drone with docker credentials, sourced from a secret. You can manage secrets in your repository settings screen in the web interface.

First create a secret that includes your Docker credentials in the format of a Docker config.json file. This file may provide credentials for multiple registries.

1  {
2 "auths": {
3 "": {
4 "auth": "4452D71687B6BC2C9389C3..."
5 }
6 }
7 }

Next, define which secrets should be used to pull private images using the image_pull_secrets attribute:

5   steps:
6 - name: build
7 image:
8 commands:
9 - go build
10 - go test
12 image_pull_secrets:
13 - dockerconfig

If you want to pull private images from Amazon Elastic Container Registry (ECR) you will need to install a registry credential plugin.

Google Container Registry Issues

If the config.json has entries for both and you should prune the file and remove the entry with the https:// prefix otherwise you will intermittently receive the following error message:

default: Error response from daemon: unauthorized: You don’t have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in:

Image Caching Behavior

The Docker daemon caches all images that is pulls, including private images. Docker does not restrict the use of cached images. An image already in the local cache can be used by any pipeline.

It is therefore possible for a pipeline to pull a private image that is cached by Docker, and for another pipeline to use this image from the cache without having credentials. Keep this in mind when pulling private images in a shared or public environment.

How did we do?