This is a demo with Nodejs - REST-API - Docker. Kindly check other branches for individual features.
git clone https://github.com/nicks9188/nodedemo.git
cd nodedemo
npm install
npm start
docker build -t node-docker-restapi .
e.g.,docker build -t nicks9188/node-docker-restapi:v1 .
docker run -d -p <your_port_number>:3000 node-docker-restapi
e.g.docker run --name node-docker-restapi -p 9000:3000 -d nicks9188/node-docker-restapi:v1
docker ps
to verify.docker logs <container_id>
to get logs- Now go to
http://<ip_address>:<your_port_number>/
to check. - To stop:
docker stop <container_id or container_name>
. E.g.docker stop node-docker-restapi
Now we have successfully dockerized our nodejs application. 👍 🤘
An account is necessary in dockerhub if want to push own image. Once we push our image, we can use it again and again.
docker login
docker push <image_name>:<tag>
e.g.,docker push nicks9188/node-docker-restapi:v1
- Now go
https://hub.docker.com/<your_account>
to check. - To use this pushed image:
docker pull <dockerhub_username>/<image_name>:<tag>
e.g.docker pull nicks9188/node-docker-restapi:v1
- To use this image again:
docker run --name <give_it_a_name> -p <your_port_no>:3000 -d nicks9188/node-docker-restapi:v1
Tips:
- Don't forget to open respective port in your host machine.
- To clear everything use
docker system prune -a
- Remember to stop container before removing everything.
We created a RESTApi app with Node.js. Created a new Docker image for this app. Pushed this image to Docker Hub for future use and We used our newely created image as a container.
From there, we are able to destroy our image and container and recreate them using our Docker Hub repository.
View this image on Hub.Docker.Com | If you liked this, give it a ⭐