Back

[SOLVED] Function on same network than docker services

  • 0
  • Self Hosted
Bouahaza
1 Jun, 2023, 12:50

I create a support post for my question here : https://discord.com/channels/564160730845151244/564160731327758347/1113760474341838868

"Is it a way to have function on same docker network than appwrite / mariadb / redis / influxdb / others docker services ? To avoid hosts mapping (or network hit)"

To be able to connect redis via redis://redis, to call appwrite sdk with http://appwrite/v1 (and not domain name), etc. => Use docker network

TL;DR
Solution: To have functions on the same docker network as Appwrite, mariadb, redis, influxdb, and other docker services, you can follow these steps: 1. Run your function on the "appwrite" network instead of the default "runtimes" network. 2. Reload the infrastructure by running the command `docker compose up -d` after making any changes. 3. Alternatively, you can edit the `.env` file and set the value of `OPEN_RUNTIMES_NETWORK` to `appwrite_appwrite`, which adds all functions to the main network. 4. Add the "runtimes" network to
Binyamin
1 Jun, 2023, 12:51

Is this on a self-hosted Appwrite instance, Or on Appwrite cloud?

Bouahaza
1 Jun, 2023, 12:54

Self hosted

Binyamin
1 Jun, 2023, 12:55

Then you have two options to achieve that. I'll write you in detail in couple of minutes

Binyamin
1 Jun, 2023, 13:03

Appwrite docker compose utilize three networks (docker network is like a virtual switch)

  • gateway - The default and not in use
  • appwrite - Composed all of appwrite services and the executor - the container that runs the runtimes.
  • runtimes - An isolated network between the executor and any dynamiclly created runtimes. Like in the picture

The reason for that is to be able to isolated a - could-be-risky - code from the server.

Binyamin
1 Jun, 2023, 13:05

So if you do want your function to share to access the main network you can either add the runtimes network to any service in your docker-compose.yml file that you want to be accessible from the functions one, for example to redis and mariadb

TypeScript
  mariadb:
    image: mariadb:10.7 # fix issues when upgrading using: mysql_upgrade -u root -p
    container_name: appwrite-mariadb
    <<: *x-logging
    restart: unless-stopped
    networks:
      - appwrite
      - runtimes
    volumes:
      - appwrite-mariadb:/var/lib/mysql:rw
    environment:
      - MYSQL_ROOT_PASSWORD=${_APP_DB_ROOT_PASS}
      - MYSQL_DATABASE=${_APP_DB_SCHEMA}
      - MYSQL_USER=${_APP_DB_USER}
      - MYSQL_PASSWORD=${_APP_DB_PASS}
    command: 'mysqld --innodb-flush-method=fsync' 

  redis:
    image: redis:7.0.4-alpine
    container_name: appwrite-redis
    <<: *x-logging
    restart: unless-stopped
    command: >
      redis-server
      --maxmemory            512mb
      --maxmemory-policy     allkeys-lru
      --maxmemory-samples    5
    networks:
      - appwrite
      - runtimes
    volumes:
      - appwrite-redis:/data:rw
Binyamin
1 Jun, 2023, 13:06

Or you can edit the .env file and set the value of OPEN_RUNTIMES_NETWORK to:

TypeScript
OPEN_RUNTIMES_NETWORK=appwrite_appwrite

And then all the function will be added to the main network.

Binyamin
1 Jun, 2023, 13:07

After any change let docker reload the infrastructure by running

TypeScript
docker compose up -d
Bouahaza
1 Jun, 2023, 13:14

Oh don't understand that runtimes is internal network for function. i trie with "appwrite" network while appwrite-executor already on appwrite network It's works, ty 🙂

Bouahaza
1 Jun, 2023, 13:15

[SOLVED] Function on same network than docker services

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