/database-back-front-setup

Docker & docker-compose project setup. Using NodeJS with express, nodemon, ReactJS and mongoDB

Primary LanguageJavaScript

Spin up docker containers steps

Docker React NodeJS Express.js MongoDB

Includes a simple CRUD app to test everything out before moving on

With docker-compose: docker-compose up

Withought docker-compose:

1. Mongo db database

docker run -d --rm --name mongodb --network goals-net -v data:/data/db -e MONGO_INITDB_ROOT_USERNAME=username -e MONGO_INITDB_ROOT_PASSWORD=pass mongo

Breakdown:

docker run
-d detached mode
-rm remove container when stoped
--name mongodb
--network goals-net (to assign to a network)
-v data:/data/db (to persist data)
-e MONGO_INITDB_ROOT_USERNAME=username
-e MONGO_INITDB_ROOT_PASSWORD=pass
mongo (to call the mongo image)

2. backend - Create image and run the container using the Dockerfile

a. Build the image

cd backend/
docker build -t goals-node .

Breakdown

docker build
-t goals-node (assign a tag name)
. (current directory)

b. Run the container

docker run -p 80:80 --name goals-backend --network goals-net -d --rm -v /web/docker-practice/multi-01-starting-setup/backend:/app -v logs:/app/logs -v /app/node_modules -e MONGODB_USERNAME=username -e MONGODB_PASSWORD=pass goals-node

Breakdown

docker run
-p 80:80 (expose port outside of the container)
--name goals-backend
--network goals-net (to assign to a network)
-d detached mode
-rm remove container when stoped
-v /web/docker-practice/multi-01-starting-setup/backend:/app (write file changes to /app)
-v logs:/app/logs (persist logs)
-v /app/node_modules (do not ovewrite node_modules with host file empty node_modules folder)
-e MONGODB_USERNAME=username
-e MONGODB_PASSWORD=pass
goals-node (to call the node image)

3. frontend - Create image and run the container using the Dockerfile

a. Build the image

cd frontend/
docker build -t goals-react .

Breakdown

docker build
-t goals-react (assign a tag name)
. (current directory)

b. Run the container

docker run -p 3000:3000 --rm -it --name goals-frontend -v /web/docker-practice/multi-01-starting-setup/frontend/src:/app/src -v /app/node_modules goals-react

Breakdown

docker run
-p 3000:3000 (expose port outside of the container)
-rm remove container when stoped
-it interactive mode
--name goals-frontend
-v /web/docker-practice/multi-01-starting-setup/frontend/src:/app/src
-v /app/node_modules
goals-react (to call the node image)