From what I can tell the firestore client has to be running on the same machine as the emulator, otherwise you end up with a gRPC error: endpoint is neither UDS or TCP loopback address
This makes running the firestore client and emulator in different docker containers impossible (well not exactly - see the monkeypatch).
The reason that this happens is that the client creates local_credentials which gRPC enforces are only used for connections via the loopback adapter or unix sockets.
Description of my setup:
docker container1: Our app which connects to firestore emulator
docker container2: firestore emulator
Possible solutions:
- Use an insecure channel to talk to the emulator
- Create proper credentials to talk to the emulator
My initial thoughts are: just use insecure channel, it is only the emulator. But that might be missing something.
For anyone seeing this issue and wondering if there is a temporary workaround, I'm using this monkeypatch for our testing setup:
import grpc
from google.cloud.firestore_v1.base_client import BaseClient
def monkey_patch_firestore_emulator():
def _emulator_channel(self, transport):
if "GrpcAsyncIOTransport" in str(transport.__name__):
return grpc.aio.insecure_channel(self._emulator_host)
else:
return grpc.insecure_channel(self._emulator_host)
BaseClient._emulator_channel = _emulator_channel
monkey_patch_firestore_emulator()