Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Google Firestore Emulator with Docker-Compose

I am trying to run my Node project as well as the Firestore Emulator with docker-compose locally in a dev environment.

I have a Dockerfile for my Node project that looks like this:


WORKDIR /app

ADD package*.json ./

RUN npm install

ADD bin ./bin

CMD [ "npm", "run", "dev" ]

Then I have a seperate Dockerfile called Dockerfile.firestorefor containerizing the Firestore Emulator. This Dockerfile looks like this:

FROM node:alpine

RUN apk add openjdk11

RUN npm install -g firebase-tools

WORKDIR /app

CMD [ "firebase", "--project=xrechnung-app", "emulators:start", "--only", "firestore" ]

The docker-compose.yml is written in the following way:

version: "3"
services:
  api:
    image: api
    build:
      context: api
      dockerfile: Dockerfile.dev
    depends_on:
      - db
    environment:
      - PORT=3000
    ports:
      - 3000:3000
    volumes:
      - ./api/src:/app/src
  db:
    image: firestore
    build:
      context: api
      dockerfile: Dockerfile.firestore
    ports:
      - 4000:4000
      - 8080:8080
    volumes:
      - .cache/firebase/emulators/:/app/.cache/firebase/emulators/ 

I'm not sure about the last two lines but I found a hint in the Google Cloud docs that this could prevent multiple downloads of the emulator.

When spinning the container up with docker-compose up the Node project runs without problem and is available at localhost:3000. Also the Emulator spins up. The console logs that its running. But I can't make it available on the prescribed ports (4000 and 8080)

Did anyone try a similar thing already? I appreciate your help.

like image 448
Moritz Laube Avatar asked Jan 24 '23 11:01

Moritz Laube


1 Answers

You probably need to set the host in the firebase.json file, like this:

{
    "emulators": {
        "firestore": {
            "port": 8080,
            "host": "0.0.0.0"
        }
    }
}

By default, the emulator runs only for localhost.

like image 62
Luiz Fernando da Silva Avatar answered Jan 27 '23 01:01

Luiz Fernando da Silva