Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2951

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T10:11:06+00:00 2024-11-26T10:11:06+00:00

Dockerize NodeJS

  • 61k

How to dockerize nodejs app

Step 1: Install Docker

To begin with, it’s required to have Docker on your computer. You can download Docker Desktop from the below link and once it’s downloaded and installed successfully, launch the Docker Desktop on your computer.

Step 2: Create a containerised application

The next step is to containerise your application using Docker. To containerise your application you need to have a Dockerfile that is written in YAML. Let’s create a Dockerfile using node as the base image.

I created a simple Node.js application and my working directory contains the below files.

hello-world   - app.js   - package-lock.json   - package.json 
Enter fullscreen mode Exit fullscreen mode

Then I need to create a Dockerfile inside this directory.

FROM node:10.23-alpine  WORKDIR /usr/src/app  COPY package*.json ./  RUN npm install  COPY . .  EXPOSE 8080  CMD ["node", "app.js"] 
Enter fullscreen mode Exit fullscreen mode

After you add the Dockerfile, you can create the docker image for your application. Use the below command for that [make sure you’re in the same directory where your Dockerfile resides].

$ docker build . -t <image-name> Eg: $ docker build . -t node-app 
Enter fullscreen mode Exit fullscreen mode

Step 3: Push your image to a Container Registry

For this demonstration, I am using Docker Hub as the container registry. But you can choose any other container registry as you prefer.

To start with, go to Docker Hub and create a new account. Then sign in and go to Repositories > Create Repository. Add a Name to your repository [you can also add a description to your repository but it’s optional] and you can choose whether it keeps as a public or a private repository [if you’re using a free plan, you can create only one private repository in your account].

Then you need to log in to your Docker Hub account using your terminal. For that, use the below command and provide your credentials where necessary.

$ docker login <container-registry-name> -u <username> -p <password> 
Enter fullscreen mode Exit fullscreen mode

This is the general command which you can use to log into your account. But the drawback of using this command is, you have to enter your password in plain text. Therefore, use one of the following commands so that your password will not be visible even on the terminal.

$ docker login <container-registry-name> // then hit enter & provide your username and password - OR - $ docker login <container-registry-name> -u <username> // then hit enter and provide your password 
Enter fullscreen mode Exit fullscreen mode

Since I’m using Docker Hub as the container registry you can use docker login command on the terminal and provide credentials without specifying the container registry name.

Eg: type docker login and hit enter $ docker login Username: <username> Password: <password> // provide credentials and hit enter 
Enter fullscreen mode Exit fullscreen mode

After you get Login Succeeded as the output on your terminal, you can start docker tagging and docker pushing.

docker tag command help you to give a tag to your docker image while docker push command pushes it into the Docker Hub. Let’s see how to use these commands on the terminal.

$ docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] SOURCE_IMAGE[:TAG] - you can keep this as your local image TARGET_IMAGE[:TAG] - <username>/<image-name>:<tag> Eg: $ docker tag node-app mikej/node-app:v1.0 
Enter fullscreen mode Exit fullscreen mode

The above command will tag your image and next you can use the docker push command as below and it will push your image or a repository to a registry.

$ docker push --help Usage: docker push [OPTIONS] NAME[:TAG] Push an image or a repository to a registry Options: --disable-content-trust   Skip image signing (default true) Eg: $ docker push mikej/node-app:v1.0  
Enter fullscreen mode Exit fullscreen mode

dockerjavascriptnodewebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.