Back

Docker mount bind or named volume to function container

  • 0
  • Self Hosted
Vinicius Brito
6 May, 2024, 18:26

I'm trying to make code in a function be able to see a named volume declared in my docker compose or a bind mount also in my docker compose, the goal is for the function to work with some permanent files external to it.

I cannot make it see anything because these temp runtimes apparently are created and disposed dynamically instead of being declared in the docker compose file.

In my host I saw this /tmp/appwrite-executor-6575176f390e0cb6479b-662a67aaa7d9a3d3f2e0/src$ ls code.tar.gz hello.txt

So the folder "appwrite-executor-6575176f390e0cb6479b-662a67aaa7d9a3d3f2e0" is a folder created specifically for that function's deployment, each function version has one.

And in the container runtime I got /tmp: code.tar.gz hello.txt

The question is, where in Appwrite's code or declaration files I can mount a directory so my function sees another folder in the host? I have looked in Executor.php but apparently it is not handling that directly

TL;DR
Developers want to bind a named volume or mount to their function container in Docker to work with external files like a dev Sveltekit app. They are trying to make changes that immediately reflect in the Sveltekit app but are unsure how to access these files within the function. They considered other options like creating a custom API container but prefer keeping the code within the function. The unsupported hack involves creating temporary runtimes dynamically in a folder created for each function's deployment. The developers seek guidance on where in Appwrite's code or declaration files they can mount a directory to make their function see another folder in the host. Solution: The
Steven
6 May, 2024, 18:31

You really shouldn't be doing this...

Steven
6 May, 2024, 18:32

Something like this is an unsupported hack and may break in the future

Vinicius Brito
6 May, 2024, 18:36

I see

Vinicius Brito
6 May, 2024, 18:40

How else could this be achieved, for a function to see files external to it? I thought about other options but all of them seem disadvantageous. For example if I create a custom API container in the network just for that then I will lose the function's surrounding features like execution report etc. I really want to keep my code in there.

Steven
6 May, 2024, 18:42

Why do you need this external file? What is it?

Vinicius Brito
6 May, 2024, 18:43

they're source code files for a dev version of a Sveltekit app. I want to programmatically make changes to them so they are immediately reflected through Sveltekit's standard hot module reloading.

Vinicius Brito
6 May, 2024, 18:43

I'm creating a web app editor

Vinicius Brito
6 May, 2024, 18:44

So user interacts with a GUI, appwrite function edits file according to that, web app changes. That's the flow.

Vinicius Brito
6 May, 2024, 18:45

They both live in the same server and same docker network

Vinicius Brito
6 May, 2024, 18:47

I tried named volumes at first but no way I could dynamically add one to the temp function container. Then I realized something similar to this happens with the host mount path, but I can't find where that is managed. I understand it is not an official API, I don't mind being "downstream" and modifying appwrite's source code or dockerfiles.

Steven
6 May, 2024, 18:47

My first thought is storing it in a document instead

Vinicius Brito
6 May, 2024, 18:48

Yeah but then the web server loses the files πŸ˜…

Steven
6 May, 2024, 18:48

The file would be locally managed and updated with data from the document

Vinicius Brito
6 May, 2024, 18:50

I don't see how the file would be accessible by the sveltekit server that way

Vinicius Brito
6 May, 2024, 18:50

I mean, I still* πŸ˜‹

Vinicius Brito
6 May, 2024, 18:51

I will try to check out how the file storage works and report back

Vinicius Brito
6 May, 2024, 18:51

Maybe I'm missing some possibility there

Vinicius Brito
6 May, 2024, 18:51

Thanks for the attention!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more