I want to reuse the layers from a docker image on two different machines in the following way:
Therefore,
Machine 1:
I build this following image:
FROM node:13-slim
COPY package.json package.json
docker build . -t <registry>/test-docker-image:latest
docker push <registry>/test-docker-image:latest
Machine 2
docker pull <registry>/test-docker-image:latest
If I run docker build .
on this machine the layers are not reused from the pulled image.
Is there a way to reuse the layers from the pulled image in the docker build
?
Similar issue:
There is the following thread on GitHub that describes something similar, but this describes the issue between sharing layers between docker build
and docker-compose build
. https://github.com/docker/compose/issues/883
To trust the layers of a pulled image that wasn't built locally, you need -cache-from
, e.g.:
docker build --cache-from=<registry>/test-docker-image:latest -t newimg:latest .
Docker won't trust pulled images by default to avoid a malicious image that claims to provide layers for an image you may build while actually including malicious content in that layer.
For more details on args to docker build
, see: https://docs.docker.com/engine/reference/commandline/build/