Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase serve in docker container works for functions but not hosting

Tags:

I've set up the following container Dockerfile:

FROM devillex/docker-firebase

ENV USER=app

RUN apt-get update && apt-get install -y openssl \
        libssl-dev \
        bash \
        less \
        vim \
        gnupg \
        curl \
        net-tools \
        apt-transport-https \
        ca-certificates; \
    CLOUD_SDK_REPO="cloud-sdk-$(grep VERSION_CODENAME /etc/os-release | cut -d '=' -f 2)" &&\
    echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list &&\
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -; \
    apt-get update && apt-get install -y \
        google-cloud-sdk \
        google-cloud-sdk-cloud-build-local &&\
    gcloud config set project request-a-dance

RUN adduser --disabled-password --gecos "" --shell /bin/bash $USER &&\
    mkdir /home/app/src &&\
    npm install firebase-tools mocha standard

USER app
WORKDIR /home/app/src

EXPOSE 5000 5001 9005

With an accompanying docker-compose.yml file:

version: '3.3'
services:
  firebase:
    image: firebase:local
    hostname: "firebase-local"
    build:
      context: ../..
      dockerfile: docker/local/Dockerfile
    volumes:
      - ~/.config:/home/app/.config
      - ~/.bash_aliases:/home/app/.bash_aliases:ro
      - ~/.bashrc:/home/app/.bashrc:ro
      - ../../src:/home/app/src/
    ports:
        - 5000:5080
        - 5001:5001
        - 9005:9005
    tty: true

I ran through the firebase init process inside my container image and now I have the following file structure inside the src directory:

|- .firebase
|- .firebaserc
|- .gitignore
|- firebase-debug.log
|- firebase.json
|- firestore.indexes.json
|- firestore.rules
|- functions
  |- index.js
  |- node_modules
  |- package.json
  |- package-lock.json
|- public
  |- index.html

I ran firebase deploy and when I visited the url for my hosted app, the browser returned the contents of public/index.html

However when I now run firebase serve -o 0.0.0.0 inside the running docker container, requests to 0.0.0.0:5001 return:

// 20190920055855
// http://0.0.0.0:5001/

{
  "status": "alive"
}

And here is the problem: requests to 0.0.0.0:5000 return to the browser:

This page isn’t working 
0.0.0.0 didn’t send any data.
ERR_EMPTY_RESPONSE

I've read through other answers on stackoverlfow such as firebase serve in docker container not visible to host os but it seems like this should be an all or nothing deal, both hosting and functions should fail or work but not functions work while hosting fails.

I'm fairly certain that something is off within my firebase.json hosting config, but given that it works when deployed I'm not sure how that would be.

like image 882
Noah Goodrich Avatar asked Sep 20 '19 12:09

Noah Goodrich


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 firebase Host server?

The Firebase CLI makes it easy to set up a new Hosting project, run a local development server, and deploy content.

Can we Host dynamic website on firebase?

Pair Cloud Functions with Firebase Hosting to generate and serve your dynamic content or build REST APIs as microservices. Cloud Functions for Firebase lets you automatically run backend code in response to HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment.

Does firebase Hosting support Python?

Then, using Firebase Hosting, you can direct HTTPS requests to trigger your containerized app. Cloud Run supports several languages (including Go, Node. js, Python, and Java), giving you the flexibility to use the programming language and framework of your choice.


1 Answers

Have you spot the line

ports:
    - 5000:5080

Maybe should - 5000:5000 not 5080?

like image 77
zzeroo Avatar answered Oct 08 '22 16:10

zzeroo