Re-use base image in later build steps

Hey :slight_smile:

I’d like to re-use a base image in later build steps.

Let’s suppose we build some base image…

kind: pipeline
type: docker
name: build

steps:
  - name: build-base
    image: plugins/docker
    settings:
      repo: my.repo.com/images/base
      registry: my.repo.com
      dockerfile: ./build/base.Dockerfile
      auto_tag: true

…and then we build some more images based upon the previous one:

  - name: build-A
    image: plugins/docker
    settings:
      repo: my.repo.com/images/a
      registry: my.repo.com
      dockerfile: ./build/a.Dockerfile
      auto_tag: true

  - name: build-B
    image: plugins/docker
    settings:
      repo: my.repo.com/images/b
      registry: my.repo.com
      dockerfile: ./build/b.Dockerfile
      auto_tag: true

So both, a.Dockerfile and b.Dockerfile, start with:

FROM my.repo.com/images/base

Currently, both build steps, build-A and build-B, re-pull base image from my.repo.com, resulting in loads of unnecessary traffic and time spent.

How can I get build-A and build-B to use a local cache of base image? It was built in the very same pipeline, so subsequent steps should not re-pull each time (image we have 20 of such images that use the same base -> would re-pull base 20 times).

The docker plugin referenced in your example uses docker-in-docker and is completely isolated and ephemeral. It does not share the host machine docker cache, for security reasons.

If you are finding this plugin does not suite your needs you have the following options:

  1. interact directly with the host machine docker daemon by mounting a docker socket, as shown here https://docs.drone.io/pipeline/docker/examples/services/docker/
  2. interact directly with a docker-in-docker daemon, using services, as shown here https://docs.drone.io/pipeline/docker/examples/services/docker_dind/
  3. create a custom plugin