Sign inSign up

spine3/firebase-emulator

By spine3

•Updated about 5 years ago

Google Firebase emulator.

Image
5

500K+

spine3/firebase-emulator repository overview

⁠Firebase Emulator Suite

The Firebase Emulator Suite⁠ image allows reducing the hustle of setting up and configuring the emulator manually.

The easiest way to start the emulator is to run the following command:

docker run \
  --rm \
  -p=9000:9000 \
  -p=8080:8080 \
  -p=4000:4000 \
  -p=9099:9099 \
  -p=8085:8085 \
  -p=5001:5001 \
  -p=9199:9199 \
  --env "GCP_PROJECT=<your-gcp-project>" \
  --env "ENABLE_UI=true" \
  spine3/firebase-emulator

The command above starts the container and exposes ports of all Firebase emulators.

⁠Configurations

The image is configured using a set of environment variables, and an optional shared volume with the configuration files.

The GCP_PROJECT environment variable is the only one required and holds the name of the GCP project for which the emulator is being started.

Other EMULATOR_ environment variables configure the Firebase emulators suite and use the same defaults as the emulator's suite.

Env variableServiceDefault value
RDB_EMULATOR_PORTFirebase Realtime DB9000
FIRESTORE_EMULATOR_PORTFirestore8080
UI_EMULATOR_PORTEmulator suite UI4000
UI_ENABLEDEmulator suite UItrue
AUTH_EMULATOR_PORTFirebase Authentication9099
PUBSUB_EMULATOR_PORTPub/Sub8085
FUNCTIONS_EMULATOR_PORTFirebase Functions5001
STORAGE_EMULATOR_PORTCloud Storage9199

The EMULATORS_HOST variable configures the host used by all the emulators and defaults to 0.

Inside the container, the emulator is configured using the firebase.json⁠ located within the /firebase folder. The configuration file is generated on-the-fly from the specified environment variables if none is supplied as a volume⁠.

⁠Mount custom Firebase configuration

It is also possible to mount a local firebase.json configuration to the /firebase folder and thus use any user-supplied configurations. In such case the environment variables do not have any effect.

E.g. one may want to specify dedicated RDB security rules for the emulator with the following firebase.json content and a firebase-rules.json available in the same folder as the config file:

{
  "database": {
    "rules": "firebase-rules.json"
  },
  "emulators": {
    "database": {
      "port": "9999",
      "host": "0.0.0.0"
    }
  }
}

Assuming the firebase.json and firebase-rules.json are available under the $PWD/firebase_configs/ folder one can use the following command to use her own configurations over the default:

docker run \
    --name "firebase-emulator" \    
    --publish "9999:9999" \
    --volume "$PWD/firebase_configs:/firebase" \
    --rm \
    spine3/firebase-emulator
⁠Start more emulators

With supplying a custom firebase.json one may benefit from configuring the emulators, and their respective rules as needed.

E.g. consider the following example that configures emulators with their respective setups and also starts the emulators UI⁠.

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "target": "staging",
    "public": "dist/web-ui",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "emulators": {
    "database": {
      "port": "5000",
      "host": "0.0.0.0"
    },
    "ui": {
      "port": "4000",
      "host": "0.0.0.0"
    },
    "firestore": {
      "port": "8080",
      "host": "0.0.0.0"
    },
    "auth": {
      "port": "9099",
      "host": "0.0.0.0"
    },
    "hosting": {
      "port": "50033",
      "host": "0.0.0.0"
    },
    "storage": {
      "port": "9199",
      "host": "0.0.0.0"
    }
  }
}
⁠Provide emulators baseline data

Some Firebase emulators provide a way to perform export and then import of the emulator state.

The exported data mount to the /firebase/baseline-data folder will be automatically imported by the emulators during the startup.

Tag summary

Content type

Image

Digest

Size

316.1 MB

Last updated

about 5 years ago

docker pull spine3/firebase-emulator