Setup Docker for Local Development (Firebase)

Dec 13, 2019

Install docker

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \   $(lsb_release -cs) \   stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Test Docker

sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Run Docker by non-root user

sudo groupadd docker
sudo usermod -aG docker $USER

NOTE: You need to login and logout again for the new membership permission to take effect. Else, run newgrp docker.

Test without sudo

docker run hello-world

Enable Docker to start on boot

sudo systemctl enable docker

Setup Ubuntu docker to development

docker pull ubuntu

Start Docker image with interactive shell

docker run -it ubuntu

Setup Node 8 runtime

apt install curlcurl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.shbash nodesource_setup.shapt-get install -y nodejs

Test

node -vnpm -v

Save/Commit Docker Changes

Notice the command prompt root@819af265fe19: /, where 819af265fe19 is the container id. You can check the current container id via docker ps -a (run outside of docker).

Exit docker.

exit

Save the changes as ubuntu:firebase

docker commit -m 'install nodejs & npm' <CONTAINER_ID> ubuntu:firebase

Start docker again with the saved changes

docker run -it ubuntu:firebase

Test if node installation is committed.

node -v

Install Firebase

  • Map docker directory with host directory: /code/firebase/test, thus we could use IDE at host to edit the files.
  • Map port 9005 for firebase login
  • Map port 5000 for firebase hosting
docker run -it -v /code/firebase/test:/code/firebase/test -p 9005:9005 -p 5000:5000 ubuntu:firebase

Install Firebase

npm install -g firebase-tools

Login

firebase login

Firebase init

cd /code/firebase/testfirebase init

Test Hosting

firebase serve -o 0.0.0.0

NOTE: Cannot access docker from host via localhost, thus need http://0.0.0.0:5000

Deploy

firebase deploy --only hosting

NOTE: Remember to save/commit docker image after exit, else firebase setup and installation shall be lost.

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.