{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/3199","labels_url":"https://api.github.com/repos/docker/docker/issues/3199/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/3199/comments","events_url":"https://api.github.com/repos/docker/docker/issues/3199/events","html_url":"https://github.com/docker/docker/issues/3199","id":24216908,"number":3199,"title":"`docker build -no-cache` does not consistently invalidate the cache for subsequent builds","user":{"login":"vreon","id":52548,"avatar_url":"https://avatars.githubusercontent.com/u/52548?v=3","gravatar_id":"","url":"https://api.github.com/users/vreon","html_url":"https://github.com/vreon","followers_url":"https://api.github.com/users/vreon/followers","following_url":"https://api.github.com/users/vreon/following{/other_user}","gists_url":"https://api.github.com/users/vreon/gists{/gist_id}","starred_url":"https://api.github.com/users/vreon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vreon/subscriptions","organizations_url":"https://api.github.com/users/vreon/orgs","repos_url":"https://api.github.com/users/vreon/repos","events_url":"https://api.github.com/users/vreon/events{/privacy}","received_events_url":"https://api.github.com/users/vreon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2013-12-12T23:27:31Z","updated_at":"2015-09-22T02:58:36Z","closed_at":"2013-12-12T23:29:23Z","body":"In this example, `docker build -no-cache` appears to invalidate the cache for subsequent builds:\r\n\r\n```console\r\n$ cat Dockerfile\r\nFROM ubuntu:12.10\r\nRUN date > builddate\r\n$ docker build -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN date > builddate\r\n ---> Running in cb5a9c443588\r\n ---> 9259bb0663e7\r\nSuccessfully built 9259bb0663e7\r\n$ docker build -no-cache -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN date > builddate\r\n ---> Running in 411ace38ef1f\r\n ---> 237318dc283c\r\nSuccessfully built 237318dc283c\r\n$ docker build -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN date > builddate\r\n ---> Using cache\r\n ---> 237318dc283c\r\nSuccessfully built 237318dc283c\r\n```\r\n\r\n```\r\ntl;dr: 9259bb0663e7, 237318dc283c, 237318dc283c\r\n```\r\n\r\n\"Awesome,\" you'd think, \"`-no-cache` is a nice way to force a full rebuild and account for the occasional RUN that isn't actually deterministic.\"\r\n\r\nBut then you try it with a slightly different RUN instruction:\r\n\r\n```console\r\n$ cat Dockerfile\r\nFROM ubuntu:12.10\r\nRUN echo `date` > builddate\r\n$ docker build -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN echo `date` > builddate\r\n ---> Running in 0c320266f660\r\n ---> 1c732f0b8836\r\nSuccessfully built 1c732f0b8836\r\n$ docker build -no-cache -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN echo `date` > builddate\r\n ---> Running in 67d2a2ae033a\r\n ---> f59e6459f768\r\nSuccessfully built f59e6459f768\r\n$ docker build -t vreon/cachetest .\r\nUploading context 10240 bytes\r\nStep 1 : FROM ubuntu:12.10\r\n ---> b750fe79269d\r\nStep 2 : RUN echo `date` > builddate\r\n ---> Using cache\r\n ---> 1c732f0b8836\r\nSuccessfully built 1c732f0b8836\r\n```\r\n\r\n```\r\ntl;dr: 1c732f0b8836, f59e6459f768, 1c732f0b8836\r\n```\r\n\r\nSo now `-no-cache` appears to *not* invalidate the cache -- the third build used the images generated by the first. Essentially, the first time you use `-no-cache`, you have to keep using `-no-cache` on all subsequent builds, or you risk reusing a layer you thought invalidated.\r\n\r\n```console\r\n$ docker version\r\nClient version: 0.7.1\r\nGo version (client): go1.2\r\nGit commit (client): e39d35d\r\nServer version: 0.7.1\r\nGit commit (server): e39d35d\r\nGo version (server): go1.2\r\nLast stable version: 0.7.1\r\n$ docker info\r\nContainers: 49\r\nImages: 50\r\nDriver: aufs\r\n Root Dir: /mnt/archive/docker/aufs\r\n Dirs: 151\r\nWARNING: No swap limit support\r\n```"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/142167153","html_url":"https://github.com/docker/docker/issues/3199#issuecomment-142167153","issue_url":"https://api.github.com/repos/docker/docker/issues/3199","id":142167153,"user":{"login":"borromeotlhs","id":1448570,"avatar_url":"https://avatars.githubusercontent.com/u/1448570?v=3","gravatar_id":"","url":"https://api.github.com/users/borromeotlhs","html_url":"https://github.com/borromeotlhs","followers_url":"https://api.github.com/users/borromeotlhs/followers","following_url":"https://api.github.com/users/borromeotlhs/following{/other_user}","gists_url":"https://api.github.com/users/borromeotlhs/gists{/gist_id}","starred_url":"https://api.github.com/users/borromeotlhs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borromeotlhs/subscriptions","organizations_url":"https://api.github.com/users/borromeotlhs/orgs","repos_url":"https://api.github.com/users/borromeotlhs/repos","events_url":"https://api.github.com/users/borromeotlhs/events{/privacy}","received_events_url":"https://api.github.com/users/borromeotlhs/received_events","type":"User","site_admin":false},"created_at":"2015-09-22T02:58:36Z","updated_at":"2015-09-22T02:58:36Z","body":"Doesn't this raise the fact that if @vreon is correct, that you risk having inconsistent cache results in builds?  The only way, then, is to always use -no-cache to ensure you NEVER use a cache at all.  When, in fact, I would like to have a command that invalidates a cache entry for a specific RUN command per Dockerfile/image build at the very least.  \r\n\r\nCan we at least have a mechanism to list how many entries from a Dockerfile/build are in the cache, and allow for invalidating those entries?"}}