Can a docker registry service be used for caching images between steps?

Here’s a simplified snapshot of a .drone.yml file that illustrates what I’d like to do:

kind: pipeline
type: docker
name: ci

  - name: build_docker
    image: plugins/docker
      repo: local-docker-registry:5000/test/myapp
      dockerfile: Dockerfile
      registry: local-docker-registry:5000
      insecure: true
        - "${DRONE_COMMIT:0:8}"

  - name: test
    image: local-docker-registry:5000/test/myapp:${DRONE_COMMIT:0:8}

  - name: local-docker-registry
    image: registry:2
      - 5000

Basically, I need somewhere to push my built image so it can be used in later steps. It does not need to be published, and will not be used by CD pipelines. A private registry in the cloud is one option, but it’s slow and a waste of space and network traffic to be pushing things up to a persistent registry if the images will not be used. I’d like to use a registry running as a service to avoid these issues, but I can’t figure out how to get it to work.

In my kubernetes-runner-based Drone environment, it just hangs at the test step indefinitely with no logs or errors, but on another POC Drone server that’s not using Kubernetes runners, I see the following message on the “test” step:

 Error response from daemon: Get https://localdockerregistry:5000/v2/: dial tcp: lookup localdockerregistry on x.x.x.x: no such host

The Docker daemon itself doesn’t know how to resolve the service name, which makes sense, but I’m struggling to come up with solutions or workarounds.

I know questions similar to this have been asked multiple times, but I didn’t find this particular approach mentioned; maybe that’s because it’s a bad idea :man_shrugging:. Here are a few related topics though:

It seems like our use of the Kubernetes runners present some interesting challenges, and combined with the use of other services in our drone.yml file, maybe it’s not possible? @bradrydzewski commented in that second topic in 2019 that there’s no good way to build a Docker image and then test the Docker image (with Kubernetes runner); is that still the case?

This would not work because the registry service exists inside a container which has network isolation and cannot be accessed by the host machine docker daemon, which is responsible for pulling images and starting pipeline step containers. Instead you may consider mounting the host machine docker socket to build, and then subsequently publish images. Example here: