skip to Main Content

Since docker layers are just filesystems is it possible to reuse a specific layer directly outside of cache build.
I mean imagesA has some layers that are layers that can be used by imageX. Is such a sharing/reuse even possible?

2

Answers


  1. You cannot just copy-paste layers from one image to another.

    The closest options you can do in order to reuse Docker layers are:

    • reuse an image by specifying the FROM <image_name:version> in the Dockerfile and use it as base image to add your layers.

    • use the --cache-from option during the build to force to use a specific image, such as the command docker build --cache-from=<registry>/image:version. --cache-from allows to consider a specific image as part of it’s build cache and Docker will use that specified image in case the current build have layers in common.

    Login or Signup to reply.
  2. Is it possible to share layers between multiple images? Yes, that’s how base images work.

    The question you didn’t ask (probably because it would be off topic): is there tooling that lets you pick specific layers to add to another image? Not that I’m aware of, and supporting that tooling would be a nightmare of user requests to know why the image they created this way is broken. E.g. there’s nothing stopping you from building a manifest that merges the layers of a debian and alpine image together. But there’s zero guarantee that such an image would work and not have unexpected results.

    If you wanted to do this, it would be up to you to do the blob copy/mount between repositories (on the same registry that’s a server side link). And then you would create the image config and manifest with the layers listed.

    The closest I’ve seen to do something like this are tools that rebase images, swapping out the layers of one base image for another, typically for a rapid upgrade without going through the full image build process. That’s seen with tools like buildpacks, crane, and regclient.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search