Back

call a docker container from/as a function

  • 0
  • Functions
Loic Devaux
6 Jul, 2023, 14:14

There are solutions, time consuming though. It requires you to be selfhosted.

TL;DR
The user wants to call a Docker container from within a function. The support team confirms that there is no direct support for running arbitrary Docker images. They suggest implementing an Appwrite function or creating a REST service on the private Docker container. Another option is to dive into the Appwrite executor source code to run a command directly on the container, but this is time-consuming and risky. The user can also manually create a new Dockerfile or use a tool like includeimage to merge the third-party Docker image with an openruntime image. These solutions require self-hosting.
Loic Devaux
6 Jul, 2023, 14:15

Merge your third party docker image with an openruntime image

Loic Devaux
6 Jul, 2023, 14:17

If you are not on ARM you can use https://github.com/bergkvist/includeimage which worked well for me

Loic Devaux
6 Jul, 2023, 14:18

otherwise you can create a Dockerfile with something like

Loic Devaux
6 Jul, 2023, 14:18

FROM openruntimes/node:v2-16.0 FROM myrep/myimage COPY --from=0 / /

Loic Devaux
6 Jul, 2023, 14:19

it works but it creates a large image

Loic Devaux
6 Jul, 2023, 14:20

or you can manually create a new Dockerfile adding the things you need (more complicated)

Loic Devaux
6 Jul, 2023, 14:22

in order for appwrite to use this new image as a base image for running functions you need to tag it with the same tag

Loic Devaux
6 Jul, 2023, 14:22

in my example it would be openruntimes/node:v2-16.0

Loic Devaux
6 Jul, 2023, 14:24

then you can call your command on your custom container with the child_process node package

Loic Devaux
6 Jul, 2023, 14:25

inside an appwrite nodejs cloud function

Loic Devaux
6 Jul, 2023, 14:27

the other solutions I would think of is to create a REST service on your private docker container with the technology you prefer so you can access via http from your cloud function

Loic Devaux
6 Jul, 2023, 14:36

a last option is to dive into the guts of appwrite executor source code ( php) and tweak things there so you can run a command directly on your container. You will end up with a good knowledge of appwrites container orchestration and flexibility to do what you want at the very low level but it might be time consuming and the risks to break things are high I think

Drake
6 Jul, 2023, 16:20

Function to call a docker container? What exactly do you mean? And are you on cloud?

Victor
6 Jul, 2023, 17:50

No. On self hosted environment. Someone provides me a closed docker container with the functionality I want to use in my function.

It is not all the time running, just one-shot-style of a private algorithm.

Victor
6 Jul, 2023, 17:52

This would be interesting, not sure whether they will provide me access to the the dockerfile, and also would complicate the CI/CD a lot, but I will keep it in mind

Victor
6 Jul, 2023, 17:54

It sounds the most reasonable, I should double check whether I can see it in the same network or how isolated is the function call from the local system.

Drake
6 Jul, 2023, 17:54

How exactly are you supposed to use this docker image?

Victor
6 Jul, 2023, 18:08

Get params via rest API, if I have to use the command line, execute docker command with those, wait to end, save on database the result

Drake
6 Jul, 2023, 18:09

Rest API nice. So you'll need to host that somewhere and then your Appwrite function can make an http request to it

Victor
6 Jul, 2023, 18:11

So, no direct support, I guess I should code it myself

Victor
6 Jul, 2023, 18:12

I would have expected a special kind of function which does that lifting for me, takes care of the warmup times, stores results, etc

Victor
6 Jul, 2023, 18:12

Well thank you

Drake
6 Jul, 2023, 18:19

Appwrite functions do that but you have to implement an Appwrite function: https://appwrite.io/docs/functions#writingYourOwnFunction

We don't support running an arbitrary docker image if that's what you were looking for

Victor
6 Jul, 2023, 21:11

Well, exactly that. I guess it will be tricky to preinitialize it… thank you for the support

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