Reputation: 10473
I'm confused about some docker cache behavior I'm seeing.
First I do a docker build, then push the image to a repository, and then I delete all my docker data locally (I'm running docker in a VM on OSX, so I destroy and re-create the VM). Then I pull the image that I just pushed to the repository.
Now, I make any change at all to my code, e.g. add a newline to the README. When I run docker build, none of the steps are cached. It runs all the steps one by one from the beginning.
Of course, I would expect any COPY .
step to be invalidated since I have updated the code, but even the steps before that are invalidated.
Why does this happen?
UPDATE:
Here's my output (anonymized a bit).
There are no command line arguments, this happens when I just run docker build .
Step 1 : FROM 123456.dkr.ecr.us-east-1.amazonaws.com/foo:0.1.1
0.1.1: foo
d89e1bee20d9: Already exists
9e0bc8a71bde: Already exists
27aa681c95e5: Already exists
a3ed95caeb02: Already exists
1f23dc7f328b: Already exists
7c5e36b70451: Already exists
0844dd833da6: Already exists
8017b7feecce: Already exists
0dd824b407cc: Already exists
ecfa07005844: Already exists
697248412260: Already exists
df6663ccf76d: Already exists
Digest: sha256:823221727843f32d1a52879aa57e40e02f4db2b31a2344384fc0307fa85c2b52
Status: Downloaded newer image for 123456.dkr.ecr.us-east-1.amazonaws.com/foo:0.1.1
---> b6b907685beb
Step 2 : RUN curl https://example.com > /file
---> Running in 1f912826e4c8
OK
Where it says that it "Downloaded newer image" for the "foo" base image, could that be where the problem is? As you can see, all the layers already exist at that point. So it's strange that it thinks it has downloaded a newer image, maybe that's related to why the following steps aren't cached?
Upvotes: 1
Views: 295
Reputation: 2761
Deleting the VM also deletes all images pulled and built from your terminal. This includes cached layers. This is expected behavior since Docker is not actually running in your host machine (OS X). Docker Engine is actually running inside the VM and your Docker client CLI is talking to Engine via an API. Think of your VM as a Docker server and your CLI as a Docker client. Because Docker Engine runs in the VM; the cached layers, pulled images, and all other data stored in the VM will be deleted along with the VM when you delete it.
Upvotes: 1