Promoted Tuna DApp From Local to Docker container along with Mongo container

Venkata Thota
Nov 1 · 4 min read

From my last post we have seen how to use Hyperledger Tuna example by adding traditional way of login page flavor using nodejs and MongoDB.

In this post we will see how that local distributed application can be containerized and using MongoDB container instead of cloud MongoDB.


Download the code from Git.

Download Mongo db image and make changes to connection in App:

docker pull mongo

Change the Mongo DB connection string from cloud to local in TunaApp/TunaApp/config/keys.js file

module.exports = {
'MongoURI' : 'mongodb://mongo:27017/tuna'
}

Dockerization of App:

From the downloaded code consider only TunaApp folder and move startFabric.sh file out side (Don’t delete the file ). This file is not required inside the app image. And change “cd ../basic-network to cd basic-network” in startFabric.sh.

To build a docker image create Dockerfile in the root directory of the application code base:

FROM node:10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json
COPY package*.json ./
RUN npm install# Bundle app source
COPY . .
EXPOSE 5000CMD [ "node", "app.js" ]

Now run the below command to create Docker image

docker build -t ervamsi/tunaapp:0.0.1 .

Now our image got created with repository name ervamsi/tunaapp and tag 0.0.1


Its time to update the Hyperledger out of the box, tuna app docker compose file by adding application and mongo db entries.

Edit TunaApp/basic-network/docker-compose.yml

mongo:
container_name: mongo
image: mongo:latest
ports:
- 27017:27017
networks:
- basic
tunaapp:
container_name: tunaapp
image: ervamsi/tunaapp:0.0.1
tty: true
working_dir: /usr/src/app
command: node app.js
volumes:
- ${HOME}/.hfc-key-store:/usr/src/app/certs
ports:
- 5000:5000
networks:
- basic
depends_on:
- orderer.example.com
- peer0.org1.example.com
- mongo

Now we have below images ready

Last but not least check the folder structure should be like below. I renamed TunaApp folder to tunaDocker

Now run startFabric.sh

./startFabric.sh
docker ps -a

Go to http://192.168.214.177:5000

Note: I am using VM (IP: 192.168.214.177) running on my windows for this project, If you are working on docker running directly on host machine, you can access the application http://localhost:5000

Now you can do user creation, tuna add, change owner of tuna, query single or all tuna. Please refer my previous post for details on navigation.

Check the new user creation details in Mongo DB container:

docker exec -it 3214c1be1c97 bash

Here 3214c1be1c97 is mongo db CONTAINER ID.

root@3214c1be1c97:/# mongo
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
tuna 0.000GB
> use tuna
switched to db tuna
> show collections
users
> db.users.find({})
{ "_id" : ObjectId("5dbaddb5dde29295538eb88a"), "name" : "Venkata Thota", "email" : "venkata.thota@email.com", "password" : "$2a$10$g.wL4l5P26B0YPjnZvstBOKhdebE4BBpiY6vV1SIWfIG0vRXY9YZy", "date" : ISODate("2019-10-31T13:12:21.851Z"), "__v" : 0, "HLSecret" : "kgXJGkysecSY" }

If you face any problems, download the ready code from here for reference.

May be I will go for create HA Cluster using Kubernetes and promote this App.

May be go for Helm charts to create deployment file for kubernetes HA cluster creation in single shot……

Stay tuned…………………………………………………

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade