Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running firebase functions inside a docker container for development purpose

I would like to develop and test a google firebase cloud functions in a docker container. Here is my Dockerfile:

FROM node:6.11.5
WORKDIR /workspace

RUN npm install -g firebase-tools eslint babel-cli

ADD functions-source/package*.json functions-source/
RUN npm --prefix ./functions-source install

ADD ./package*.json ./
RUN npm install
ENV GOOGLE_APPLICATION_CREDENTIALS /workspace/keys/default-appengine-service-key.json
EXPOSE 9005 5000

I build the image above with this command

docker build --tag dewey-nguyen:latest .

Then start a docker container with this command:

docker run -p 9005:9005 -p 5000:5000 -o 0.0.0.0 -v `pwd`:/workspace -it dewey-nguyen:latest /bin/bash

When I got inside of the container, I log in to firebase with this command:

firebase login

and I was able to sign in to firebase in the browser (http://localhost:9005/...) from host machine.

When I run firebase serve --only functions --debug inside of my container, I see all functions are green:

✔  functions: auth: http://localhost:5000/dewey-nguyen/us-central1/auth
✔  functions: myInformedDelivery: http://localhost:5000/dewey-nguyen/us-central1/myInformedDelivery
✔  functions: authCallback: http://localhost:5000/dewey-nguyen/us-central1/authCallback
✔  functions: checkInformedDeliveryEmails: http://localhost:5000/dewey-nguyen/us-central1/checkInformedDeliveryEmails

But I am not able to access http://localhost:5000/dewey-nguyen/us-central1/auth from the host browser with ERR_EMPTY_RESPONSE error returned.

Does anyone have a clue?

like image 292
Dewey Avatar asked Jun 30 '18 16:06

Dewey


People also ask

Does Firebase work with Docker?

Automate building with Firebase and Build Docker Image on every push to GitHub, recurrently or manually. Set up the Continuous Integration and Delivery (CI/CD) workflow with GitHub, Firebase, Build Docker Image and Buddy in minutes. Build test & deploy instantly.

Can Cloud Functions run containers?

Cloud Build then automatically builds your code into a container image and pushes that image to a image registry (either Container Registry or Artifact Registry). Cloud Functions accesses this image when it needs to run the container to execute your function.

What can you do with Firebase Functions?

While it's expected that Firebase apps will use Cloud Functions in unique ways to meet their unique requirements, typical use cases might fall into these areas: Notify users when something interesting happens. Perform database sanitization and maintenance. Execute intensive tasks in the cloud instead of in your app.

Is Firebase a Microservice?

Firebase Hosting integrates with serverless computing options, including Cloud Functions for Firebase and Cloud Run. Using Firebase Hosting with these options, you can host microservices by directing HTTPS requests to trigger your functions and containerized apps to run in a managed, secure environment.


1 Answers

I've just went the same problem here, fixed by using the following command firebase serve --only functions -o 0.0.0.0. Using this option you still can access by localhost on your host machine.

You can also map your .config folder, something like -v "${HOME}/.config":"/root/.config" to keep your logged account, because your firebase session is stored in there.

like image 136
Victor Miguez Avatar answered Oct 04 '22 00:10

Victor Miguez