Added the BINDCONTEXT dockerfile instruction#5369
Conversation
closes moby#3056 The `BINDCONTEXT` instruction will arrange for the context to be mounted at the location `<mountpoint>` inside the container during the subsequent `RUN` commands. Docker-DCO-1.1-Signed-off-by: Anthony Baire <Anthony.Baire@irisa.fr> (github: a-ba)
|
Hi, This is a very nice idea.
It might be nice to make a read-only mount. So that container can't mess up the files. |
|
Very nice to have this during building!
👍 for something like |
I would make BINDCONTEXT by default readonly |
|
What about something like BINDCONTEXT /path:rw ? I think we also need to wait for some clarification from the core |
|
+1, during my container builds I need access to a private ssh key, which afterwards I don't need anymore. Due to the layering this key gets baked into the image and I have to be careful about protecting the generated binaries. With this change the secret information is no longer in the images and the protection requirements for the whole infrastructure (private registry, hosting servers) become way simpler. |
|
I am also very interested in this for the "I need 2gb of build artifacts to make a 10mb binary" angle. |
|
Would it be possible to achieve the same with a Just wondering if a new instruction needs to be added to the Dockerfile vocabulary, while it performs similar functionality as the existing Some way to remove a volume from within a Dockerfile would be useful in these cases. |
|
VOLUME+ADD do not seem to give the expected result. The context lands in the image anyway, and it still requires a copy. |
A way to remove the volume should be, without regard to this issue. E.g. I often mount |
|
@a-ba that's what I remembered happening. The question here is; is that by design or a bug? From my point of view, content added to a volume should not end up in an image. This may be a misinterpretation on my side. If volumes would not end-up in an image, most cases could be handled by using a volume in the Dockerfile, which would keep things simple. Maybe there are other situations that are not handled that I'm overseeing of course. @crosbymichael @shykes Should content added to a Note; If the |
AFAIK, by design. There is an feature request to init a volume from the image content. But volume being not part of the image is a main it's use case. In fact VOLUME command is an annotation for future
Docker file must not contain something about host file system. And must be secure. So some malicious |
|
The issue with VOLUME is that the data is only available during the |
There was a problem hiding this comment.
I think it would be good to expand on what happens outside of docker build time to make sure there's no ambiguity for our more creative readers :)
What dastardly things happen if I BINDCONTXT /etc, - I presume that allows me to feel safe that the final image will have a clean /etc just like the FROM container had.
if I BINDCONTEXT /non-existant-dir will that dir exist in the final image, but be empty?
fun feature.
Ok, clear, maybe this could be re-considered? Build creates intermediate containers, why not have it use a VOLUME as well?
Agreed, Dockerfile should not be aware about the host filesystem. Implementing the
Not sure if security is a major issue here; the content of a Dockerfile is readable. IMO, |
I'm not in charge for that. But what's the use case? If you need some files, you put them in context, then explicitly copy to the image.
The primary use case is building untrusted Dockerfile by trusted user :) |
Isn't that what this PR is about? Using files inside an image, without copying them to the image (or at least without them taking up space inside the image)? When running a container, volumes provide exactly that, but volumes are not available during build. |
This pull request allows to mount "context". I.e. a directory where Dockerfile is. Currenly this directory is uploaded to docker daemon fully. But sometimes context is huge, and it's inefficient to tar it and send it to daemon and untar again. Also sometimes context contains many files that don't actually needed (e.g. All in all you may think of this patch as an optimization of what can already be done now. |
|
I can't help but think, that this functionality would be better served by a |
v0.11.1 Conflicts: docs/sources/reference/builder.md
|
I think the benefit of this over an explicit |
|
Is this still being worked on? I unfortunately am not technically adept enough to contribute to this effort, but I would like to voice my desire to see this feature in a future Docker release. I frequently find myself in situations where I need to build from source within the image, but using the ADD instruction to copy the source files to the container results in inflation of the image size, which is very undesirable for my applications. The alternative I am forced to use then is to run in interactive mode and use -v to mount the directory containing the source files, but this gets very tricky to automate. |
|
I'm 👍 on this. This is a good alternative to the secrets stuff that @vbatts is currently working on. |
|
Is this in the schedule to be merged? It's a great feature and would really allow us to better utilize the build cache if we didn't invalidate everything with |
|
+1 on this. We've been hurting for a way to mount a volume during container build for a long time. Our current solution is a set of scripts that (poorly) approximate a Dockerfile. Our use case is caching Maven dependencies between builds and keeping them out of our images. |
|
some thoughts about this PR :
|
…-bindcontext Conflicts: builder/internals.go integration-cli/docker_cli_build_test.go
Docker-DCO-1.1-Signed-off-by: Anthony Baire <Anthony.Baire@irisa.fr> (github: a-ba)
7f57d19 to
d425e05
Compare
|
Tagged as UX for next design session. |
|
Design review with @icecrime NOTE: this is only a design review. Let's please reach agreement on design before going back and forth on code details. This is to avoid wasting your time. I agree on the idea. But the word
I would expect the docs to say something like: "ADDTMP works exactly like ADD, except the source directory is only temporarily added to the container, and will be removed, along with any changes, at the end of the build". I would really emphasize "works exactly like". We should make sure that all artifacts of ADD are preserved in ADDTMP unless documented otherwise. For example, the added directory should be writeable, and changes should persist across build steps; source and destination paths should be resolved following the same rules (choice of file vs. directory etc). And so on. |
|
@shykes with exactly like Just asking, and to prevent wrong expectations. |
|
We're closing this one in favor of an ulterior docs PR: maintainers (@crosbymichael @unclejack @tiborvass) are against a new Dockerfile verb for this purpose, and are suggesting other possibilities (such as having the context always bind-mounted in the container as part of a build process). |
|
@icecrime can you ref that PR? I'd like to keep following along on this issue |
|
@mkscrg there is none afaict, but as soon as there is one, we'll add a reference to it on this one. |
|
Always bind-mounting the context won't work. Once the context is |
|
@tianon good point |
|
What if we essentially copied what MOUNT-CONTEXT some-dir /somewhere-in-the-image
MOUNT-CONTEXT some/sub/directory /somewhere-else
MOUNT-CONTEXT . /ALL-THE-THINGS |
|
i am still maintaining the patch at https://github.com/a-ba/docker/tree/3056-bindcontext (up to date with 1.6.0) since we have no alternative for the moment ADDTMP would be fine for us though it does not help in handling large files (but that part should rather be addressed by caching/CoW, eg. #9553) |
|
@a-ba 1) Is the idea for your "BINDCONTEXT" to be silently ignored if the local context is not available? |
There is always a context: at least it contains the Dockerfile. If there is only a Dockerfile, BINDCONTEXT would not be ignored however it would be mostly useless.
yes
There are two problems with letting the user bind an arbitrary directory from the machine: security (it gives root access) and side-effects (we have no guarantee that the data will not be altered after they are fingerprinted and before they are used in the build)
"Context generally refers to metadata or something else" but in the case of docker it refers to the archive we ship to the server for the build. It is used everywhere in the documentation. However I agree that the word CONTEXT should not be in the command name, but for an other reason: to make it consistent with the other commands that use the context : ADD and COPY |
|
Now I am thinking of another solution : why not just mount /tmp from a temporary external volume during the whole build ? Thus, instead of writing: we would just write : By convention everything in /tmp is discarded at the end of the build. It is easy to understand and it does not require to introduce a new keyword. The only downside is that it breaks old Dockerfile where the user expects to have something remaining in /tmp/ in the final image (but is it a real concern?) |
|
@a-ba please see the roadmap; https://github.com/docker/docker/blob/master/ROADMAP.md There's a feature freeze on the Dockerfile syntax, because we're in the process of moving the "builder" client-side, which will allow alternative implementations to the Dockerfile, and more flexibility. |
|
The /tmp use case would be useless if you're wanting to have a local apt or portage repository available (which you don't want in the image.) In the case of the apt respository - Ubuntu knows to fetch it from a certain path, or from the internet if that path is not available. |
|
The naming of a Has the builder been forked? |
closes #3056
The
BINDCONTEXT <mountpoint>instruction arranges for the context to be mounted at the location<mountpoint>inside the container during the subsequentRUNcommands.The context is mounted in read-write mode. This is convenient when building something from sources located in the context since only files that are explicitly installed will persist in the image. Everything else (sources, intermediate files,...) is wiped out when the build is over.
The command is also useful when dealing with a voluminous files. Using BINDCONTEXT instead of ADD avoid making extra copies of temporary files and avoids keeping them in the final image. Depending on the case, this can mitigate #2224 and #332.
There are two outstanding questions: