Dockerize React/NodeJS App with Postgres
Sometimes you will want to run both a frontend React app, a backend NodeJS server, and a Postgress database from the same host.
Quick Start
Docker compose has been an excellent way to achieve this while working with serveral different applications that will need to work together (See https://docs.docker.com/compose/). Once you’ve installed Docker, compose should be installed as well.
Cd into your React project and create a Docker file with:
1 | touch Dockerfile |
Add the following contents:
1 | FROM node |
Now cd into your NodeJS project and create another Dockerfile with the following contents:
1 | FROM node |
Now that you have set up your Dockerfiles, you are now ready to create your docker-compose file. I usually place this file in a directory above the project directories:
1 | version: "3" |
You’ll need to make some edits to this file regarding the foldernames. This file assumes you have a folder named react-app and node-server.
After this, return to the directory with the compose file and you should be able to execute:
1 | docker-compose up |
And Boom! You are now a docker ninja!