#Bind mount
1 messages · Page 1 of 1 (latest)
The mounts in dagger aren't like bind mounts in docker, which are bidirectional. These are more like snapshots. What you need in this case is a cache volume which you can use in with_mounted_cache.
@buoyant warren oh that's a surprise as a user. Is there an easy way to get data out of the cache volume?
Another doc, in the quickstart: https://docs.dagger.io/quickstart/635927/caching
It's a common misconception to equate dagger with docker run, but it's more like a Dockerfile's RUN. Both are using buildkit underneath (https://docs.docker.com/engine/reference/builder/#run---mount). In a Dockerfile, a bind mount can allow writes to the mount, but they are discarded. The withMountedCache method works more like RUN --mount-type=cache (https://docs.docker.com/engine/reference/builder/#run---mounttypecache).
The example you provided in #general message isn't clarifying to me what your use case is though. In that simple example there's no need for the mount. Do you expect to mount it again in another place in an implicit way to get those files?
\cc @strong void
Oh, from re-reading your list above you want to get data out of what a service adds to a directory. You can later add the cache mount to another container to with_exec something on those files, or cp them to another location if you need to export it. Depends on what you need to do with that data.
I think I was able to achieve that through a cache mount. Accessing the cache data directly was a challenge so I had to mount it into a dummy container that dumped out.
If you're using dagger 0.9.3 it's easier to achieve this by using the new service lifecycle APIs. You can just stop the service after your pipeline is finished and then use the Export method directly from the service container
@strong void how do I get the container from the service?
a Container can be changed to a Service with the AsService method.
So if you have something like this:
// create HTTP service container with exposed port 8080
httpCtr := client.Container().
From("python").
WithDirectory("/srv", client.Directory().WithNewFile("index.html", "Hello, world!")).
WithWorkdir("/srv").
WithExec([]string{"python", "-m", "http.server", "8080"}).
WithExposedPort(8080)
httpSrv := httpCtr.AsService()
^ there you have the httpCtr and httpSrv variables
you just need to remember to call Stop on the service variable before exporting any files