How to run Firebase emulator without a hassle!

ERBO Engineering
3 min readDec 12, 2021

--

“TLDR: How to set up the Firebase emulator without having to install java JDK. Just check the solution chapter and let docker work for YOU

Photo by Marek Szturc on Unsplash

The problem

When starting out with your cool Firebase project, it's good practice to run your project locally before ever deploying that bad boy to production.

So when you read the delightful documentation from Firebase and install the emulator software through NPM, which works lovely. But the moment you set it up:
“Storage Emulator has exited because java is not installed” 😨
pops up.

Storage Emulator has exited because java is not installed
Storage Emulator has exited because java is not installed

Now most of us are not Java developers and do not have the JDK or other pesky java dependencies installed and also would rather avoid it ;). Let’s face it, maybe 10 billion devices run java, but nobody wants to install it anymore.

So how we solve this?

The solution 💪

We dockerize the whole shebang and call it a day. This sounds easy, and if you are familiar with docker, it actually is.

To prepare:
Make sure you have installed docker and docker-compose on your system, and have a Firebase project.

> If you don’t have a firebase project setup you can run firebase initor use our example project from our github.

This solution is composed out of the following steps:

  • Update your firebase.json to look like the following
firebase.json file used to configure the emulator
  • writing a Dockerfile that builds an image containing the full emulator suite and it’s dependencies
  • to easily start the container, we use a docker-compose file that manages exposing the ports, building the image and mounting the volume

We assume that your docker is up and running, and it’s time to write the Dockerfile.

Docker file for running Firebase emulators

You can build this docker container using docker build . --tag firebase-emulator and then run it with this long ass command

docker run -p 9199:9199 -p 9099:9099 -p 9098:9098 -p 5001:5001 -v /path/to/project:/app firebase-emulator

But nobody would like to run this command.
Let alone memorize this command each time they want to run their emulator. So this is where docker-compose comes in!

docker-compose.yml for running the Firebase emulator

Now you can run your sweet Firebase emulator suite with docker-compose up and bam it just works!

Treats for our readers🎅

To close off this blog post, we want to leave the readers that came this far with a little treat.

  1. When building Firebase functions using typescript, you can automatically build on changes by running npm run build -- --watch in your functions directory
  2. Checkout our example project at our GitHub

Sources

  1. https://firebase.google.com/docs/emulator-suite
  2. https://docs.docker.com/engine/install/
  3. https://docs.docker.com/compose/install/
  4. https://docs.docker.com/engine/reference/builder/
  5. https://gist.github.com/ERBO-Engineering/343a30ab7a71e9a1d48ec0826e4fec8a
  6. https://gist.github.com/ERBO-Engineering/848071451a7858c09f87f1045321068a
  7. https://firebase.google.com/docs/functions/get-started

Follow us for more articles in the near future. 🚀

We plan to publish an article at least once a month containing all kinds of interesting tech topics. Ranging from “Improving your development environment” to “Introduction into embedded Linux” and many more.

--

--

ERBO Engineering

At ERBO Engineering we believe that, with the right amount of expertise and knowledge combined with great enthusiasm, we are able to overcome every hurdle