Dockerize a node express app
Lets start with building a basic node express app. These are the file I have inside my project directory.
Lets navigate the content of files one by one. .dockerignore
.gitignore
Dockerfile
app.js
package.json and package-lock.json is with default configration. Did not change any its content. It just generate while executing
npm install express
Now will build a docker image, with the help of the instruction mention in docker file.
Can see above command gives
means a docker image created successfully, with the name node-express-app:latest We can verify that, and check using 'docker images' or 'docker image ls' command
Now, with the help of the image node-express-app, will create a running container out of it. And also expose the express app at same PORT we defined in the app.js file.
-d is detached mode -p is port first 3000 is the host 3000 Port, and another 3000 represent the container 3000 Port, in which container is exposed and running. To check, all the container running and stopped
Can see the node-express-app is with Up status. Now, will access the page to see, if we get the content from node express app. will request http://localhost:3000
Also, we can verify the same by navigating to the browser
This is a simple way to Dockerize node express app. And then we can easily push this to Docker hub . which then be publicly available to pull and run in any machine. Without configuring or need additional software. Just have Docker runtime engine and thats it.
To know more about, how to push the image to docker registry, refer https://motionknowledge.blogspot.com/2021/07/docker-basics.html

0 Comments