{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/31067","repository_url":"https://api.github.com/repos/docker/docker","labels_url":"https://api.github.com/repos/docker/docker/issues/31067/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/31067/comments","events_url":"https://api.github.com/repos/docker/docker/issues/31067/events","html_url":"https://github.com/docker/docker/issues/31067","id":207987708,"number":31067,"title":"Proposal: Multi-stage builds","user":{"login":"tonistiigi","id":585223,"avatar_url":"https://avatars2.githubusercontent.com/u/585223?v=3","gravatar_id":"","url":"https://api.github.com/users/tonistiigi","html_url":"https://github.com/tonistiigi","followers_url":"https://api.github.com/users/tonistiigi/followers","following_url":"https://api.github.com/users/tonistiigi/following{/other_user}","gists_url":"https://api.github.com/users/tonistiigi/gists{/gist_id}","starred_url":"https://api.github.com/users/tonistiigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonistiigi/subscriptions","organizations_url":"https://api.github.com/users/tonistiigi/orgs","repos_url":"https://api.github.com/users/tonistiigi/repos","events_url":"https://api.github.com/users/tonistiigi/events{/privacy}","received_events_url":"https://api.github.com/users/tonistiigi/received_events","type":"User","site_admin":false},"labels":[{"id":73616520,"url":"https://api.github.com/repos/docker/docker/labels/area/builder","name":"area/builder","color":"fbca04","default":false},{"id":179237833,"url":"https://api.github.com/repos/docker/docker/labels/kind/feature","name":"kind/feature","color":"AAB3AB","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-02-16T01:42:35Z","updated_at":"2017-03-08T14:34:05Z","closed_at":null,"body":"#resurrects #7149\r\n\r\nWe've been going back-and-forth among some maintainers to provide a way to provide capabilities for users to produce sleek images without the cruft of the intermediate build artifacts.\r\n\r\nWe see a lot of requests from the community for this feature and different ways how people try to work around it, most commonly with `docker cp` and re-tarring a new context or trying to combine the whole build into a single `RUN` instruction.\r\n\r\nAmong the things we discussed were rebasing to a different rootfs path, mounting or copying data from other images, using cache storage between images, squashing, subblocks inside dockerfile, invoking builder inside of dockerfile etc.\r\n\r\nEventually, we ended up on the #7149 proposal that allows switching context of a build to a directory from an existing image. The benefits of this proposal are that it least conflicts with the current design principles of Dockerfile like self-consistency, build cache, returning single target etc. while elegantly solving the small images problem\r\n\r\nWhile this proposal can be considered as a \"chained-build\" and has some limitations for describing complicated build graphs with multiple branches we have concluded that it would be best to solve that problem in a more higher level and we continue to investigate possible improvements.\r\n\r\n#### The proposal:\r\n\r\n`BUILD /path/to/context` instruction in the `Dockerfile` that switches the current build context to `/path/to/context` from the current image's rootfs.\r\n\r\n`docker build docker://image-reference[::/subdir]` that invokes a new build using the data from a specified image as a build context.\r\n\r\n#### Notes:\r\n\r\n- No previous metadata carries over to the new image after `BUILD`. The next instruction after this command needs to be `FROM`.\r\n- The other way to think about the `BUILD` instruction is as `SETCONTEXT`\r\n- The build from docker reference syntax is useful when the build is described by multiple Dockerfiles and dependencies are controlled by Makefile like utility.\r\n- Only the layers after the last `BUILD` instruction end up in the final image.\r\n- `docker build -t` would tag the last image defined at the end the Dockerfile \r\n- Some features like auto-tagging and specifying/loading a Dockerfile from new context directory have been left out and can be considered as future additions.\r\n\r\n#### Example:\r\n\r\n```\r\nFROM ubuntu\r\n\r\nRUN apt-get install build-essentials\r\nADD . /src\r\nRUN cd /src && make\r\n\r\nBUILD /src/build\r\nFROM busybox\r\nCOPY app /usr/local/bin/app\r\nEXPOSE 80\r\nENTRYPOINT /usr/local/bin/app\r\n```\r\n\r\n@icecrime @vikstrous @fermayo"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/285056440","html_url":"https://github.com/docker/docker/issues/31067#issuecomment-285056440","issue_url":"https://api.github.com/repos/docker/docker/issues/31067","id":285056440,"user":{"login":"duglin","id":1944671,"avatar_url":"https://avatars2.githubusercontent.com/u/1944671?v=3","gravatar_id":"","url":"https://api.github.com/users/duglin","html_url":"https://github.com/duglin","followers_url":"https://api.github.com/users/duglin/followers","following_url":"https://api.github.com/users/duglin/following{/other_user}","gists_url":"https://api.github.com/users/duglin/gists{/gist_id}","starred_url":"https://api.github.com/users/duglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duglin/subscriptions","organizations_url":"https://api.github.com/users/duglin/orgs","repos_url":"https://api.github.com/users/duglin/repos","events_url":"https://api.github.com/users/duglin/events{/privacy}","received_events_url":"https://api.github.com/users/duglin/received_events","type":"User","site_admin":false},"created_at":"2017-03-08T14:34:05Z","updated_at":"2017-03-08T14:34:05Z","body":"e.g. accessing a secret during the build w/o worrying about copying it into a layer."}}
{"actor":{"display_login":"duglin"}}