{"id":18947626,"url":"https://github.com/yousafkhamza/nodejs-dockerfile","last_synced_at":"2025-04-15T23:30:24.655Z","repository":{"id":195965557,"uuid":"376201198","full_name":"yousafkhamza/nodejs-dockerfile","owner":"yousafkhamza","description":"It's a sample Dockerfile. Also, it's creating a small size container that includes nodejs with a sample hello world. Maybe it's helpful for beginners.","archived":false,"fork":false,"pushed_at":"2021-07-11T09:11:53.000Z","size":34,"stargazers_count":4,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T04:11:18.885Z","etag":null,"topics":["docker","docker-image","dockerfile","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yousafkhamza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-06-12T04:27:07.000Z","updated_at":"2021-09-10T06:35:12.000Z","dependencies_parsed_at":"2023-09-20T20:13:42.849Z","dependency_job_id":null,"html_url":"https://github.com/yousafkhamza/nodejs-dockerfile","commit_stats":null,"previous_names":["yousafkhamza/nodejs-dockerfile"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fnodejs-dockerfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fnodejs-dockerfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fnodejs-dockerfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2Fnodejs-dockerfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yousafkhamza","download_url":"https://codeload.github.com/yousafkhamza/nodejs-dockerfile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249172986,"owners_count":21224481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-image","dockerfile","nodejs"],"created_at":"2024-11-08T13:10:41.893Z","updated_at":"2025-04-15T23:30:24.392Z","avatar_url":"https://github.com/yousafkhamza.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nodejs Containeraisation (Docker)\n[![Builds](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)\n\n---\n# Description\n\nIt's a sample Dockerfile. Also, it's creating a small size container that includes nodejs with a sample hello world. Maybe it's helpful for beginners.\n\n---\n\n# Features\n\n- It's a sample of a nodejs Dockerfile for image creating\n- it's a very small size consumed odejs container (alpine OS)\n\n---\n# Pre-Requests\n\n- Need to install docker on your machine \n\n---\n# Installation \n\n- [Docker installtion](\"https://docs.docker.com/engine/install/ubuntu/\") \n- Pre-installed [docker terminal](\"https://labs.play-with-docker.com/\") for biginners and it used for lerning purpose.\n\n---\n# How to build a image with Dockerfile\n_Steps:_\n```sh\nyum install docker -y\nyum install git -y\ngit clone https://github.com/yousafkhamza/nodejs-dockerfile.git\ncd nodejs-dockerfile\n```\n_building steps:_\n```sh\ndocker build -t \u003cyour_image_name:tag\u003e . \n#eg: docker build -t nodejs:1.1 .\ndocker image ls \u003c------------------ image will list here\n```\n\n### Screenshots\n\n_Downloading the docker file from Git and build a image_ \n![alt text](https://i.ibb.co/xqHf7m4/image-build-1.png)\n\n_Build completed and image is created_\n![alt text](https://i.ibb.co/yBRj2sk/image-build-2.png)\n\n---\n# How to build a Container from the image\n\n_Stpes_\n\n```sh\ndocker container run --name node -p 80:3000 -d nodejs:1.1\ndocker container ls  \u003c--------- container listing with status\nArgument explanation:\n--name \u003c----- Using for container name otherwise docker select a random name\n-p     \u003c----- Using port publish like our local port assign for that container it means localport forwards to docker container\n-d     \u003c----- Detach the container otherwise its try to enter the container\n```\n### Screenshots \n\n_Build a container from previously created image_\n\n![alt text](https://i.ibb.co/C24qGWw/container-intilaze-from-image-and-its-up.png)\n\n_Container running on 80 port and output_\n\n![alt text](https://i.ibb.co/xqHf7m4/image-build-1.png)\n![alt text](https://i.ibb.co/jwLzj4Q/output.png)\n\n# _Additional Informations_\n\n---\n## _Push Image to Docker Hub (upload docker image to registry)_\n_I have uploaded the same Docker image to [Docker hub](\"https://hub.docker.com/\"). Also, why we use docker hub it's a registry of docker and we can upload our image to docker hub and then we can download the image any system like a git hub_\n### _Steps_\n1. _How to login Docker hub_\n```sh\ndocker login \u003c----------- login with your credentials which you use in docker hub\n```\n\n_Docker Login_\n![alt text](https://i.ibb.co/L8kRdz4/docker-login.png)\n\n2. _Docker Push_\n\u003e _docker push is working with your docker hub username so you need to change the image name with your username_\n\n```sh\ndocker tag nodejs:1.1  \u003cyour_username\u003e/\u003cimage_name\u003e:tag\ndocker push \u003cyour_username\u003e/\u003cimage_name\u003e:tag\n# eg:\ndocker tag nodejs:1.1 yousafkhamza/nodejs:1.1        \u003c------- tag is using for rename but the old image is alive but both are using same image id\ndocker push yousafkhamza/nodejs:1.1\n```\n\n_Docker tag and push_\n![alt text](https://i.ibb.co/HzRxVCb/tag-and-push.png)\n\n---\n\n## _How to pull this image from Docker hub(Download image from registry)_\n_Download image from Docker hub and it no needs to login docker hub._\n```sh\ndocker pull \u003cyour_username\u003e/\u003cimage_name\u003e:tag\n# eg:\ndocker pull yousafkhamza/nodejs:1.1\n```\n\n_Docker pull from Docker hub_\n![alt text](https://i.ibb.co/gZkb9RD/pull.png)\n\n---\n\n# Docker File Explanation\n```sh\nFROM alpine:3.8               \u003c-------- Base Image\nRUN mkdir /var/node/          \u003c-------- RUN is using for exicute shell command\nWORKDIR /var/node/            \u003c-------- Image working directory\nCOPY ./app.js ./              \u003c-------- Copy node file to WD\nRUN apk update\nRUN apk add nodejs npm        \u003c-------- nodejs and npm installtion\nRUN npm init -y\nRUN npm install express       \u003c-------- nodejs module installtion \nEXPOSE 3000                   \u003c-------- Just expose which port we use in container\nENTRYPOINT [ \"node\" ]         \u003c--------- EntryPoint we using our image default command and if you need to change container runing time you can use \"docker run --entrypoint sh \u003cimage\u003e:tag\" when you enter this your image default command is shell \nCMD [ \"app.js\" ]              \u003c--------- CMD is working the same image default command but when you use ENTRYPOINT at that time this following entry point and it works as a argument of ENTRYPOINT eg: \"node app.js\"\n```\n---\n# Conclusion\n\nIt's just a basic explanation for installing docker and how write Docker file and image and container building with a smallest nodejs. I hope you guys are understood. If you have any doubts regarding the Repo please ping me via LinkedIn.\n\n\n### ⚙️ Connect with Me\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"mailto:yousaf.k.hamza@gmail.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Gmail-D14836?style=for-the-badge\u0026logo=gmail\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://www.linkedin.com/in/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://www.instagram.com/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge\u0026logo=instagram\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://wa.me/%2B917736720639?text=This%20message%20from%20GitHub.\"\u003e\u003cimg src=\"https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white\"/\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fnodejs-dockerfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyousafkhamza%2Fnodejs-dockerfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fnodejs-dockerfile/lists"}