-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dockerfile: add run --mount support #442
Conversation
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Supports binds from images and context and cache mounts. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
mounts := instructions.GetMounts(c) | ||
|
||
for i, mount := range mounts { | ||
if mount.From == "" && mount.Type == "cache" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is cache
a mount type support by moby ? I guess it's for directory like .m2
, … so 👍
How Go is configured to use |
case "type": | ||
allowedTypes := map[string]struct{}{ | ||
"cache": {}, | ||
"bind": {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling bind-mount by default may cause security issue?
Maybe better to require daemon-side configuration?
As described in moby/moby#32507 these are custom mount types with builder specific meaning. Cache is builder specific but of course, it works with moby as well (with no updates required for the current integration branch). The bind (default) is bind between stages or build context not a directory on the host.
Default |
OMG - does this finally mean I'll be able to mount a SSH socket file during docker build ? |
moby/moby#32507 defines mounts from context, stages and images, tmpfs mounts and persistent cache mounts that can be used for application specific cache. ssh sharing is covered in #262 |
So... this was merged 4 months ago. I followed about 16 (closed) pull requests and 23 issues all referencing each other like a game of "whodunnit" in 2nd grade, finally arriving here. I switched to Generally specking though... Is this out yet? Edit: Fun fact. When I check for updates in Docker for Mac, I get |
@voltechs you need to enable buildkit as a builder, and use the mkdir foo && cd foo
cat <<EOF > Dockerfile
# syntax=docker/dockerfile:1.0-experimental
FROM busybox
RUN --mount=target=/foo cat /foo/Dockerfile
EOF
DOCKER_BUILDKIT=1 docker build -t foo .
|
I've read through #262 and I've read through this, and I still can't figure out how to do ssh sharing, I'm on 18.09 edge as well - since |
@tonistiigi just to check is it still possible to use this to mount a location on the host's filesystem with the current code on master? So something like this:
Looking at https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md#experimental-syntaxes it seems to suggest it doesn't work with host volume mounts which was something that this PR did seem to implement. Also it seems like it's not possible to choose where to mount it to, is that correct? |
Host-mount is unlikely to be implemented. Why do you need to mount the host filesystem? |
When will |
@rcjsuen you mean without the You can use it already with |
Hi, @thaJeztah. Thanks for getting back to me. I meant as an official feature of Docker without the need of the special |
@thaJeztah I'm still unable to get this to work beyond your example (which is working). I have
and it still errors with
|
@andig that's odd; what version of docker are you running? I just tried your exact example, and it works (obviously it fails building because the source isn't there, but it doesn't fail on the DOCKER_BUILDKIT=1 docker build -<<'EOF'
# syntax=docker/dockerfile:1.0-experimental
FROM golang:alpine as builder
RUN --mount=target=/root/.cache,type=cache go build -ldflags="-w -s" -a -installsuffix cgo -o /go/bin/ingress github.com/andig/ingress/cmd/ingress
EOF
|
Also note that the
I'll update the examples in this thread |
Thanks for the fast reply and the updates. For sake of other readers here's why it failed for me- additional comments above the
Without those other comments its fine... |
The |
Update: this feature was added to the experimental Dockerfile syntax
Read more about experimental Dockerfile features in the experimental.md file
This implements moby/moby#32507 (missing tmpfs support atm) as an experimental feature of Dockerfile frontend. The main
dockerfile.v0
frontend is unaffected.It can be used by building the frontend with a
dfrunmount
build tag and then loading it with either the gateway frontend or syntax directive (orgateway-devel
to run from source on development).The keys from the
--mount
options are taken from the ones supported bydocker run
. I'm not sure if we want to keep the ambiguous ones.I also ran into a case where a scratch mount would error if binded. This was explicitly validated with a test but I don't think that is required. Even though there is no use case for this we can just create an empty temporary readonly directory instead of failing the build. @ijc
example:1
example2:
https://gist.github.com/tonistiigi/0e0ab30ebf0eb6e4b82e1786d8b4dda1#file-test-dockerfile-L28
repeated builds reuse go cache
Note: The examples do not require updating to this PR. They run in master buildkit or moby integration PR.
Follow-up: need to figure out how to run tests with these features. Currently only checks that it builds.
@AkihiroSuda @tiborvass @thaJeztah @vdemeester