Open In App

Dockerizing a simple Node.js app

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The goal of this article is to show how to get a Node.js application into a Docker container.

  • First of all we will create a sample node app and then,
  • Build a Docker image of that application and run it
  • Setting up Node app
    Create a directory and run the command npm init to initialize the app and install initial dependencies

    setup

    Create a file app.js and write this code inside it.

    app

    The next step is to add Docker to it. So, create an empty file named Dockerfile and put this code inside it

    docker

    Now add .dockerignore file to prevent your local modules and logs to be copied onto your Docker image and add this two files
    ignore

    Now we need to build our Docker image and run it. This can be done by the following command :
    he
    tr


    Last Updated : 14 Oct, 2021
    Like Article
    Save Article
    Previous
    Next
    Share your thoughts in the comments
    Similar Reads