html,javascript,node.js,mondodb,mongo-express
Step 1: Create docker network
docker network create mongo-network
Step 2: start mongodb
docker run -d -p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=password \
--name mongodb \
--net mongo-network \
mongoStep 3: start mongo-express
docker run -d -p 8081:8081 \
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
-e ME_CONFIG_MONGODB_ADMINPASSWORD=password \
-e ME_CONFIG_MONGODB_SERVER=mongodb \
--net mongo-network \
--name mongo-express \
mongo-expressStep 4: open mongo-express from browser
http://localhost:8081
Step 5: create user-account db and users collection in mongo-express
Step 6: Start your nodejs application locally - go to app directory of project
npm install
node server.js
Step 7: Access you nodejs application UI from browser
http://localhost:3000
Step 1: start mongodb and mongo-express
docker-compose -f docker-compose.yaml up
You can access the mongo-express under localhost:8080 from your browser
Step 2: in mongo-express UI - create a new database "user-account"
Step 3: in mongo-express UI - create a new collection "users" in the database "user-account"
Step 4: start node server
npm install
node server.js
Step 5: access the nodejs application from browser
http://localhost:3000
To stop the container
docker-compose -f docker-compose.yaml down
docker build -t my-app:1.0 .
The dot "." at the end of the command denotes location of the Dockerfile.
Running the image: docker run my-app:1.0
CLI of Container: docker exec -it 307f8c51e365 /bin/sh
Setting the environment variables now
ls
env
- login to aws with root user
- go to ecr and create repository
- Make sure you have image in your device of container
- AWS provides the login command use from website itself of ecr repository. Prerequisite is AWS CLI and Credentials configured
- Docker Tag command now to recognize which image to push to AWS
- you can check the new image copy by docker images
- docker push now with aws command
- if you do changes in current docker file or code.. Go for building new image docker build -t my-app:1.1 . repeat the same process to Docker tag step 5. docker tag my-app:1.1 <AWS_ACCOUNT_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/my-app:1.1
- docker login is done only once.
-
AWS ECR has image my-app and Docker hub for two MongoDB images
-
Do changes as suggested in below image in docker-compose file

-
Also added in server.js for mongodb // use when starting application as docker container let mongoUrlDocker = "mongodb://admin:password@mongodb";
-
Replace all the mongoUrlLocal in server.js by mongoUrlDocker and build image again such as it is in: MongoClient.connect(mongoUrlLocal, mongoClientOptions, function (err, client) {
-
create the docker compose file in the development server, we don't have it now, by vim docker-compose.yaml and paste the same content as we have in github repo file and
-
docker-compose -f docker-compose.yaml up

