20

Docker has a cache, which is great, but all I see in the "docker build" output is either:

---> Using cache

or the output of the command (which implies it's not using the cache).

After one step in my Dockerfile (a COPY), it clearly doesn't use the cache. But I'm fairly certain nothing has changed in the folder that it's copying. (It's our application, and I run into the no-cache case even when I deploy twice in a row, for example.)

Is there any way to get Docker to tell me what it thinks changed?

I know Docker used to check timestamps for this, but that was fixed in Docker 1.8, and I'm on Docker 1.9.x here.

Timmay
  • 261
  • 1
  • 5
  • Please post your `Dockerfile` – Joel E Salas Jan 09 '16 at 04:55
  • 2
    @JoelESalas: I don't understand your request. Something as simple as `FROM ubuntu:14.04` `MAINTAINER me` `COPY /app/ /app/` will demonstrate this. And I'm not going to post my entire source code and infrastructure. – Timmay Jan 11 '16 at 21:36
  • 4
    Besides, even if looking at the Dockerfile could help, the question was how do *I* diagnose such problems. I don't want *somebody else* to look at my config and tell me the answer. I want to know what tools exist to help solve the problem. – Timmay Jan 11 '16 at 21:38
  • How sure are you that nothing is changing in that directory? – Joel E Salas Jan 12 '16 at 00:11

1 Answers1

6

Use binary search, with .dockerignore.

Add half your files to .dockerignore, and build the container. If it uses the cache for the COPY step, then you know the changed files are in the set you ignored, otherwise you know it's in the other half. Repeat this test with the set of files that has the change, until it's just one file/folder.

(Dear lazyweb: figure out some way to extend Docker to make this less painful!)

Timmay
  • 261
  • 1
  • 5
  • 3
    Sounds an okay approach for debugging something locally, thanks. In my case, I'm currently trying to debug the Docker cache in a CI environment, and I'm a bit bummed that I can't seem to find any way to make the Docker build more verbose =/ – elias May 03 '19 at 09:02
  • In my case the cache is only invalidated some times, so this approach wouldn't work – Shanteva May 12 '21 at 18:51