{"action":"created","issue":{"url":"https://api.github.com/repos/moby/moby/issues/32507","repository_url":"https://api.github.com/repos/moby/moby","labels_url":"https://api.github.com/repos/moby/moby/issues/32507/labels{/name}","comments_url":"https://api.github.com/repos/moby/moby/issues/32507/comments","events_url":"https://api.github.com/repos/moby/moby/issues/32507/events","html_url":"https://github.com/moby/moby/issues/32507","id":220814479,"node_id":"MDU6SXNzdWUyMjA4MTQ0Nzk=","number":32507,"title":"builder: Proposal: Add support for `RUN --mount`","user":{"login":"tonistiigi","id":585223,"node_id":"MDQ6VXNlcjU4NTIyMw==","avatar_url":"https://avatars1.githubusercontent.com/u/585223?v=4","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,"node_id":"MDU6TGFiZWw3MzYxNjUyMA==","url":"https://api.github.com/repos/moby/moby/labels/area/builder","name":"area/builder","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":77,"created_at":"2017-04-11T01:31:07Z","updated_at":"2018-08-04T00:40:10Z","closed_at":null,"author_association":"MEMBER","body":"This proposal is a combined from the previous discussion in #30110 #3056 #5369 https://github.com/docker/docker/issues/31067#issuecomment-284847466 #30449 \r\n , from @justincormack @duglin and many others.\r\n\r\nI propose adding an extra flag `--mount` to the `RUN` command in Dockerfile. This would make sure that certain external resources are present while the build step runs. These mounts will not end up in the final image.\r\n\r\nBuild cache for every `RUN` would be calculated same way as multi-stage build `COPY --from=` is implemented. The builder would calculate a secure hash for the source directory and validate if it is the same as in the previous invocation. If something changes in the mounted directory the `RUN` command executes again.\r\n\r\n\r\n#### Use cases:\r\n\r\nAvoid copying over files that are just needed for a build command and don't need to be in the final image. Simple example is\r\n\r\n```\r\nCOPY dir /\r\nRUN go build -o d ./dir\r\n```\r\n\r\nIn that case, the source does not need to be copied(and potentially deleted) into the image. Instead the process could use it directly: `RUN --mount=src=/dst,dest=/dst,ro=true go build ...`. \r\n\r\nMounts can also appear from other build stages using the same logic as `COPY --from`.\r\n\r\n```\r\nFROM debian AS foo\r\n...\r\nFROM alpine\r\nRUN --mount=src=/,dest=foo,from=foo ..\r\n```\r\n\r\nThis can also be used as a workaround for the `COPY --chown` issue as with mounting, no extra layer is created between copy and any other operation running in the container. `chown` isn't a primary use case for it though, and maybe should be supported separately as well.\r\n\r\nMounts from other images can only be read-only.\r\n\r\n#### Optional additional use case: tmpfs\r\n\r\nIf a command needs a place to store temporary files it would be good if it could just set some directory as `tmpfs` instead of trying to clean up after itself and doing unnecessary disk accesses.\r\n\r\n`RUN --mount=dest=foo,type=tmpfs`.\r\n\r\nIn the future, we could allow more types. It is necessary though that we don't allow anything that isn't reproducible or uses some external resource.\r\n\r\n#### Optional additional use case: shared build cache\r\n\r\nThere is a widely requested feature for providing a way to have shared cache directories between builder invocations. Usually, people would want to work around it by introducing `-v` to `docker build` but that has many downsides https://github.com/docker/docker/pull/31499#issuecomment-285447076\r\n\r\nA solution for that could be to allow exposing a special kind of mount that is mutable and can be automatically cleared by the builder.\r\n\r\n```\r\nFROM scratch AS cache-for-go\r\n\r\nFROM golang\r\nRUN --mount=dest=/go/pkg,from=cache-for-go,type=cache go build\r\n```\r\n\r\nNow everything written to `/go/pkg` by `go` would be already there next time builder runs(unless user runs `docker system prune`). The cache ID could be calculated after the program has executed, or maybe, in this case, it would be users responsibility to make sure that all data in this directory is optional and cache would only be invalidated if commands in `cache-for–go` definition change. Finding previous cache directory would be based on session ID from client like in #31829\r\n\r\n@dnephin @justincormack @duglin @tiborvass @vdemeester "},"comment":{"url":"https://api.github.com/repos/moby/moby/issues/comments/410408636","html_url":"https://github.com/moby/moby/issues/32507#issuecomment-410408636","issue_url":"https://api.github.com/repos/moby/moby/issues/32507","id":410408636,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDQwODYzNg==","user":{"login":"kenyee","id":586670,"node_id":"MDQ6VXNlcjU4NjY3MA==","avatar_url":"https://avatars2.githubusercontent.com/u/586670?v=4","gravatar_id":"","url":"https://api.github.com/users/kenyee","html_url":"https://github.com/kenyee","followers_url":"https://api.github.com/users/kenyee/followers","following_url":"https://api.github.com/users/kenyee/following{/other_user}","gists_url":"https://api.github.com/users/kenyee/gists{/gist_id}","starred_url":"https://api.github.com/users/kenyee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenyee/subscriptions","organizations_url":"https://api.github.com/users/kenyee/orgs","repos_url":"https://api.github.com/users/kenyee/repos","events_url":"https://api.github.com/users/kenyee/events{/privacy}","received_events_url":"https://api.github.com/users/kenyee/received_events","type":"User","site_admin":false},"created_at":"2018-08-04T00:40:10Z","updated_at":"2018-08-04T00:40:10Z","author_association":"NONE","body":"Is there a final list of example --mount commands or it the list the original post?  I think I used the \"---mount src=\" initially because someone posted that as an example.\r\nI'm trying to mount a subdirectory from my current directory into the container temporarily."}}
{"actor":{"display_login":"kenyee"}}