Docker – How to debug Docker cache invalidation

docker

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.

Best Answer

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!)