How to run Firebase emulator without a hassle!
“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”
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.
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 init
or 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
- 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.
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!
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.
- When building Firebase functions using typescript, you can automatically build on changes by running
npm run build -- --watch
in your functions directory - Checkout our example project at our GitHub
Sources
- https://firebase.google.com/docs/emulator-suite
- https://docs.docker.com/engine/install/
- https://docs.docker.com/compose/install/
- https://docs.docker.com/engine/reference/builder/
- https://gist.github.com/ERBO-Engineering/343a30ab7a71e9a1d48ec0826e4fec8a
- https://gist.github.com/ERBO-Engineering/848071451a7858c09f87f1045321068a
- 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.