Back

Contacting server from docker in localhost

  • 0
  • Webhooks
Silfalion
13 May, 2023, 16:54

I think this may an issue with oracle cloud itself maybe, I'll try to add the server to the same network as the worker. Would have you instructions for that, please?

TL;DR
Solution: The user was trying to make their dockerized Dart server communicate with Appwrite using a Docker network. They followed these steps: 1. Dockerized their app 2. Created a new Docker network 3. Added the app to the Docker network 4. Used `docker ps` to find the container ID of the Appwrite webhook worker 5. Added the worker to the same Docker network 6. Accessed the Dart server using `http://[NAME_OF_APP_CONTAINER]:PORT/path` Things to note: - The user could have potentially used the default Docker network called 'bridge' instead of creating a new network. -
Drake
13 May, 2023, 16:56

you shouldnt use https if your dart server doiesnt have https

Drake
13 May, 2023, 16:57

oh thats right...host.docker.internal might be a docker desktop thing

Silfalion
13 May, 2023, 16:58

It doesn't, yeah. I was getting a bit despaired for a solution so I tried everything that went through my mind lol

Silfalion
13 May, 2023, 16:58

Yeah, apparently it seems to be a windows thing as well, but I could be wrong

Drake
13 May, 2023, 17:00

how are you running your dart server? docker compose?

Silfalion
13 May, 2023, 17:01

Just executing the dart frog serve for now, was gonna containerize it after I was done testing

Drake
13 May, 2023, 17:03

oh...you cant do docker networking if its not in a container 😜

Silfalion
13 May, 2023, 17:03

Really? Lol, so have been trying all this time the wrong way xD

Silfalion
13 May, 2023, 17:03

Wait, so you can't make docker connect to the localhost?

Silfalion
13 May, 2023, 17:04

I remember having a similar problem long ago with functions, so I had to hit the domain directly instead of localhost.

Oh! So it works in Appwrite because it's a group of containers communicating with one another

Silfalion
13 May, 2023, 17:05

That's how it works?

Drake
13 May, 2023, 17:15

Yes, that's how docker networks work. You create a docker network and put docker containers in there and they can talk to each other via the container name.

Drake
13 May, 2023, 17:15

And yes, you might be able to use the server hostname to hit your dart server. The downside is your dart server might be publicly accessible then

Silfalion
13 May, 2023, 17:18

Thank you, glad to learn something new

Silfalion
13 May, 2023, 17:18

Yeah, I wanted to avoid that

Silfalion
13 May, 2023, 17:18

So this means if I containerize the dart server, I'll have to make sure it's on the same network as the Appwrite containers

Silfalion
13 May, 2023, 17:19

Rather the webhook worker

Drake
13 May, 2023, 17:30

No it should be in the same docker network as the worker because the worker is what needs to send the request to the dart server

Silfalion
13 May, 2023, 17:35

Oh ok, got you

Silfalion
13 May, 2023, 17:35

I'll try that then. Thank you so much for your help

Silfalion
13 May, 2023, 18:41

Finally was able to make them communicate, thank you <:appwriterocket:823996226894692403>

Silfalion
13 May, 2023, 18:47

For anyone finding this, I did the following steps:

  • dockerized my app
  • create a new docker network
  • added the app to this docker network
  • used docker ps to find the container id of the Appwrite webhook worker
  • add the worker to the created network
  • now in web hooks you can use http://[NAME_OF_APP_CONTAINER]:PORT/path and it will hit for you

A few things to note:

  • docker has a default network called bridge, so you may be able to use that instead of creating a new network
  • I had to explicitly rename my app container because it had an underscore in the middle, and urls (like the one you webhook too) can't have those
  • the Appwrite docker compose file has a list of networks but for some reason adding the newly created network there didn't work. As in the worker didn't autoamtically get added to that network
  • there may be a way through the bridge to communicate directly with your app, but I didn't explore that possibility

If you have questions or found an easier solution, I'm all ears:)

Drake
13 May, 2023, 19:43

I suggest using a docker compose file for your dart server so that it's easy to spin up and you can configure the network and whatnot in there.

On the appwrite side, I always suggest using a docker compose override file. With that, you can extend the Appwrite compose file to put the worker in the dart server network

Silfalion
13 May, 2023, 21:20

Yes, using docker-compose is definitely a must now

And I didn't know you can override a compose file, this is gonna make things a lot more straightforward, thank you you again

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