Creating a simple DockerFile and deploying a node app [on windows]

Let us first create a simple node.js/express app and then we will see how can we deploy the app on docker via creating docker image.

Create a file package.json and add following code for libs and dependencies

In the same folder, create a file server.js as shown below

run command $npm install to install node modules

Create a dockerfile with following code

Create a .dockerignore file to prevent your local modules and debug logs from being copied onto your Docker image and possibly overwriting modules installed within your image.

Check if docker is installed in the system by running docker -v in command prompt

Go to your project path in cmd

Build your dockerfile using following command

$docker build -t sarthak/node-web-app .

$ docker build -t <your username>/node-web-app .

Run your docker image

$ docker run -p 49160:8080 -d sarthak/node-web-app

$ docker run -p 49160:8080 -d <your username>/node-web-app

the above command with generate your container id

Enter the container via docker exec command, try ls to check files present in your container [must be same as in your node project]

try curl to hit your node app server and check the response

there it is, there is the response from the node app.

Drop your comments for any queries.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s