- Clone the repository from here. cd idtcDay1
- Go into app directory cd app
- Install required dependencies npm install
- Create docker network docker network create mongo-network
- Start mongodb container docker run -d -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password --name mongodb --net mongo-network mongo
- Start mongo-express docker run -d -p 8081:8081 -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin -e ME_CONFIG_MONGODB_ADMINPASSWORD=password --net mongo-network --name mongo-express -e ME_CONFIG_MONGODB_SERVER=mongodb mongo-express
- Open mongo-express from browser http://localhost:8081
- Create user-account database and users collection in mongo-express
- Make changes in server.js • Comment line 29 • Remove comment from line 26 • Replace mongoUrlDocker with mongoUrlLocal on line 41 and 71
- Start your nodejs application node server.js
- Access it from the browser http://localhost:3000 Till this you have successfully deployed your app locally with mongoDB container. Now you need to build your app so that you can push it to dockerhub.
- Go to docker-hub create an account.
- Create a repository my-app on docker hub
- Go to idtcDay1 directory on your PC cd ..
- Undo the changes done in server.js in step 9.
- Delete node_modules folder from app directory.
- Edit build my-app image docker build -t /my-app:1.0 .
- Edit the docker-compose.yml file 25: image: /my-app:1.0
- Start mongodb, mongo-express an my-app docker-compose -f docker-compose.yaml up
- You can access the mongo-express under localhost:8080 from your browser
- In mongo-express UI • Create a new database my-db • Create a new collection users in the database my-db
- Access the node.js application from browser http://localhost:3000
- Push your image to docker hub docker push /my-app:1.0