moby: Using --cache-from doesn't skip base image pull
Description
Steps to reproduce the issue:
docker pull myimage:latest
docker build --cache-from my-image:latest -t my-image:latest .
Describe the results you received:
Sending build context to Docker daemon 525.8 kB.8 kB
Step 1/15 : FROM node:6.10-alpine
6.10-alpine: Pulling from library/node
709515475419: Downloading [==> ] 97.51 kB/2.313 MB
92aa7b64772e: Downloading [==> ] 654.5 kB/14.96 MB
a32501522b97: Downloading [=> ] 32.77 kB/868.1 kB
...
Describe the results you expected:
Sending build context to Docker daemon 525.8 kB.8 kB
Step 1/15 : FROM node:6.10-alpine
6.10-alpine: Pulling from library/node
709515475419: Layer already exists
92aa7b64772e: Layer already exists
a32501522b97: Layer already exists
Additional information you deem important (e.g. issue happens only occasionally): Always
Output of docker version
:
Client:
Version: 1.13.0
API version: 1.25
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.0
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 49bf474
Built: Tue Jan 17 09:58:26 2017
OS/Arch: linux/amd64
Experimental: false
Output of docker info
:
Containers: 10
Running: 0
Paused: 0
Stopped: 10
Images: 26
Server Version: 1.13.0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 62
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.8.0-37-generic
Operating System: Ubuntu 16.10
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 11.64 GiB
Name: MYNAME
ID: MYID
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional environment details (AWS, VirtualBox, physical, etc.): This happens on CI also
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 40
- Comments: 25 (5 by maintainers)
Commits related to this issue
- Reuse docker layer cache It's important to also pull the base image: https://github.com/moby/moby/issues/31613 — committed to simplificator/kickstart-docker by crackofdusk 6 years ago
- Reuse docker layer cache It's important to also pull the base image: https://github.com/moby/moby/issues/31613 — committed to simplificator/kickstart-docker by crackofdusk 6 years ago
- Reuse docker layer cache It's important to also pull the base image: https://github.com/moby/moby/issues/31613 — committed to simplificator/kickstart-docker by crackofdusk 6 years ago
Ok so i’m not the only one experiencing this. I’ve spent the last 4 hours disabling
overlay
driver and creating clean runners in my Gitlab CI server, testing if that was the cause with no success.On my machine the base-image is skipped and on Gitlab CI is always pulled.
I’ve opened an issue also on Gitlab #29184 until is not clear where this bug comes from.
Confirmed
I do this work-around to avoid pulling the base image and therefore invalidating the cache layers:
In the end my pipeline looks about like this:
/Cc @tonistiigi
For when on busybox (no -P for grep):
I think I bumped into the same issue with Travis CI. After some digging, to reproduce the issue locally, I had to remove
/var/lib/docker/image/overlay2/distribution/diffid-by-digest
. It looks like this directory contains mappings to the layer IDs. When doingdocker save
it is not preserved and loading the image does not populate it. Subsequently, even though the layers for the base image are loaded, the verification of their existence fails duringdocker pull
.As a workaround, I save that directory and restore it, as part of saving the images. Here is our .travis.yml file that does it and an example build.
If it helps anyone, I was able to use cache from previous builds in the shared GitLab Runner using the docker in docker service using Buildkit:
Couple things to note:
--build-arg BUILDKIT_INLINE_CACHE=1
as the first flag ondocker build
(I might be crazy)latest
tag was actually pushed from within the dind service itselfReferences:
Update:
I didn’t have to actually pull the
latest
tag either (saves a little bit more time in the runner):+1
Maybe i’m wrong and this is not the way it should work, but from my understanding inside
myimage:latest
i’ve all the layers from the base image so even if i don’tpull mybaseimage:latest
it should use that layers to compare with the version on the registry and reuse them if the checksum is the same.