Quite recently I had a situation to build my own docker container that should trigger my node.js server application , which I need to integrate with my Hyperledger Fabric Server.
I have attempted many steps, but finally ended up with this beautiful official documentation from NodeJS(Refer it as OFFICIAL in this article)
https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
While you can build your docker container by following above article, but you may end up facing few issues. I would like to address those issue here.
Let’s get started..
Assumptions:
- You have your nodejs application setup & ready to build your containers
- You have some prior knowledge about how docker works?
- You should have your system ready with docker installed, If not follow this article to install the same ( https://docs.docker.com/install/linux/docker-ce/ubuntu/#supported-storage-drivers )
a) Setup Package.json as mentioned in OFFICIAL
b) Setup server.js as mentioned in OFFICIAL
c) Create Dockerfile as mentioned in OFFICIAL (Note, here you may make a mistake in setting up different PORT number from Server.JS and Dockerfile : Keep it same)
d) create .dockerignore file as mentioned in OFFICIAL
Build your image using this command , here node-web-app is user defined, you can name whatever you want.
docker build -t <your username>/node-web-app .
Finally run your docker using below
docker run --rm -i -t -p 49160:8080 <your username>/node-web-app
it should show up below results
Error you may hit :
- curl: (7) Failed to connect to localhost port 49160: Connection refused
Thanks for taking time to read, comment if you face any issues.
Happy to help…