#Mount a bidirectional host volume in a container

1 messages · Page 1 of 1 (latest)

neat carbon
#

Hey everybody,
I'm currently trying to allow the devs at my company to run something like dagger call postgresql --volume <some local path> up using a custom function that create a postgres container and serve it as a Service, so they can connect locally to work. The idea is to have a similar behavior than a docker-compose that mount a host folder in the container and persist the data across multiple restart. Unfortunately, when using the with_mounted_directory() function, it just copy the directory from the host system to the container and doesn't sync the data back. I saw there is a export function that allow to export the data directory back to the host system but as I serve the container as a service, I don't see how I can use the export function to export the data.

Is it an intended use of Dagger or am I trying to do something that dagger is absolutely not make for? Is it possible to do it now, and if not is it in the plan of dagger to allow to mount bidirectionally directories between the host and a container in the future?

Thank you!

verbal rampart
#

Hello 🙂

#

Unfortunately, when using the with_mounted_directory() function, it just copy the directory from the host system to the container and doesn't sync the data back.
Yes, this is by design. There's a good explanation of why it is this way in #1300820432957476916 message

jagged eagle
#

@neat carbon you can create persistent directories and mount them into a container, we call them cache volumes. You can't mount them directly from a local path though. You create one, give it a name, and dagger will persist it across runs for you.

upbeat flame
jagged eagle
#

@upbeat flame I think one-way filesync and two-way volume mounting (even though they're implemented as the same feature in docker) might end up being solved differently in Dagger. Not sure. Just thought I'd point that out.

pliant obsidian
#

One scenario where this might be useful is code generation. You can use export --path if you only generate one directory, but it gets tricky when you have a workspace with multiple projects

midnight musk
# pliant obsidian One scenario where this might be useful is code generation. You can use `export ...

You can still support this use-case. If you have a function which performs all the generations and returns a directory with all the child paths correctly populates, --path export all files where it should be.

We do this in the dagger/dagger repo with the sdk all generate function. https://github.com/dagger/dagger/blob/main/.dagger/sdk_all.go#L46

GitHub

An engine to run your pipelines in containers. Contribute to dagger/dagger development by creating an account on GitHub.

neat carbon
#

Thank you for your answers! So this is possible to support using some alternate ways, but do you think it will become a real feature in dagger? It would allow to totally drop docker-compose in favor of dagger as a local development tool, which will use the same codebase than the CICD pipelines!