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/ 
ยดยดยด
(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 runds 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.

Source: Docker Questions

LEAVE A COMMENT