I'm trying to optimize storage in my docker registry and getting problem using remote cache.
My docker file looks as follows:
FROM java:11-debian
LABEL maintainer="Me"
ENV LANG en_US.utf8
RUN addgroup --system --gid 51170 myusername
...
If I build locally multiple times cache is being used.
For Jenkins pipeline I always tag my last build with latest and pull the previous latest just before build of the current message:
docker pull artifactory/image:latest
docker build -t artifactory/image --cache-from artifactory/image:latest .
docker tag artifactory/image artifactory/image:latest
docker push artifactory/image:latest
Log output looks as follows:
...
---> f6363f58bc32
Step 2/18 : LABEL maintainer="Me"
---> Using cache
---> 54efd5e63c04
Step 3/18 : ENV LANG en_US.utf8
---> Using cache
---> 6865c5539193
Step 4/18 : RUN addgroup --system --gid 51170 myusername
Removing intermediate container f8d05d2e5f16
---> af5202782abc
...
Why RUN is not cached in case of remote cache? What are the differences between local cache and usage of --cache-from?
From https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources
To use an image as a cache source, cache metadata needs to be written into the image on creation. This can be done by setting
--build-arg BUILDKIT_INLINE_CACHE=1
when building the image. After that, the built image can be used as a cache source for subsequent builds.
Additionally, to use the Docker BuildKit, you must have DOCKER_BUILDKIT=1
in your environment. The easiest method being
DOCKER_BUILDKIT=1 docker build ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With