My take on... Making Firebase Emulators work in Docker

My take on... Making Firebase Emulators work in Docker

ยท

2 min read

Nowadays I develop mostly inside a docker container, which allows me to have a tailor made environment for each project and makes switching and sharing the environment with new teammates a breeze.

After reading a little bit about Firebase Emulators, I wanted to give it a go. Silly me when I thought it was going to be easy.

After following the steps in Firebase documentation, I could get it working sometimes. That because from time to time when I restarted the emulators I got this error message in firebase-debug.log

[debug] [2022-10-13T17:09:25.592Z] Error: listen EADDRNOTAVAIL: address not available ::1:4000
    at Server.setupListenHandle [as _listen2] (node:net:1415:21)
    at listenInCluster (node:net:1480:12)
    at doListen (node:net:1629:7)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
[error] 
[error] Error: An unexpected error has occurred.

I tried everything that came to my mind, trying to disable IPv6 from within the container, change the IP, etc.

That's when I decided to go to where I've should go in these cases, StackOverflow. I couldn't find a convincing answer so I ask a question (please note the desperation in the title). After a couple of days I didn't receive an answer so I kept looking for one.

Digging in the deepest part of the second page of Google's results, I've found a github issue just talking about this problem.

It seems the problem can be fixed setting the host and port for each emulated service in firebase.json. Some people add it for Firestore, other for PubSub, other for authentication. What did I do? I added for everything:

"auth": {
      "port": 9099,
      "host": "0.0.0.0"
    },
    "functions": {
      "port": 5001,
      "host": "0.0.0.0"
    },
    "firestore": {
      "port": 8080,
      "host": "0.0.0.0"
    },
    "hosting": {
      "port": 5000,
      "host": "0.0.0.0"
    },
    "hub": {
      "host": "0.0.0.0",
      "port": 4400
    },
    "logging": {
      "host": "0.0.0.0",
      "port": 4500
    },
    "eventarc": {
      "host": "0.0.0.0",
      "port": 9299
    },
    "ui": {
      "enabled": true,
      "port": 4000,
      "host": "0.0.0.0"
    },

And the issue is solved! In the future I'll talk about how I set a new Angular / Firebase Project with Docker.

As always, I hope you can take anything useful from this and I'd like to know your thoughts.

Feel free to reach me on LinkedIn or Twitter . ๐Ÿ‘‹๐Ÿป

Did you find this article valuable?

Support Ezequiel E. Tejada by becoming a sponsor. Any amount is appreciated!

ย