Search code examples
firebasedockerfirebase-authenticationcontainersfirebase-tools

Firebase Authentication Emulator UI in docker container doesn't work on localhost


I have this dockerfile:

FROM node:16

ADD . /src
WORKDIR /src
# Install OpenJDK-11
RUN echo 'deb http://ftp.debian.org/debian stretch-backports main' | tee /etc/apt/sources.list.d/stretch-backports.list

RUN apt-get update && \
    apt-get install -y openjdk-11-jre-headless && \
    apt-get clean;
RUN npm i -g firebase-tools
RUN firebase --version
EXPOSE 9099 4000

I have this firebase.json:

{
  "emulators": {
    "auth": {
      "port": 9099
    },
    "ui": {
      "enabled": true,
      "port": 4000
    }
  }
}

I have this docker-compose file:

version: "3.0"
services:
  firebase:
    build:  
      context: .
      dockerfile: Dockerfile.firebase-emulator
    volumes:
      - ./fb-data:/src
    ports:
      - "9099:9099"
      - "4000:4000"
    stdin_open: true
    tty: true

Then I run docker exec -it <container-id> sh and start running these commands inside:

  1. firebase login --no-localhost
  2. firebase emulators:start --project demo-test

The result is this:

enter image description here

When I access in the browser the http://localhost:4000/auth the result is:

enter image description here

Is there something wrong with the exposed docker ports?

Thx for any help!


Solution

  • After more digging, to make this work, the firebase.json needs to have the "host" attribute:

    {
      "emulators": {
        "auth": {
          "port": 9099,
          "host": "0.0.0.0"
        },
        "ui": {
          "enabled": true,
          "host": "0.0.0.0",
          "port": 4000
        }
      }
    }