How to Push a Dockerized Node.js App to a Container Registry

A Container Registry stores and lets you distribute your container images.Photo by Max Duzij on UnsplashContainerising application is a popular concept in modern software development and this concept has enabled more opportunities for the developers. A…


This content originally appeared on Level Up Coding - Medium and was authored by Randil Tennakoon

A Container Registry stores and lets you distribute your container images.

Photo by Max Duzij on Unsplash

Containerising application is a popular concept in modern software development and this concept has enabled more opportunities for the developers. After introducing open-source Kubernetes, this concept has become more interesting and it has opened various ways to integrate containerised applications with 3rd-party tools.

In this article, I will be talking about how you can push your container images to a container registry. A Container Registry is basically a repository that helps you to store your container images and allow other hosts to download your images from the registry server.

For demonstration purposes, I am using a simple Node.js application and I will go through each step from the beginning. So you can continue with me and if you’re already having a containerised image on your computer, you can start from Step 3.

Let’s get started and create a containerised Node.js application first.

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.

Docker Desktop for Mac and Windows | Docker

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

Then I need to create a Dockerfile inside this directory.

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

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>

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

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

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

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

Conclusion

Congratulations 🎉

You have successfully pushed your dockerized Node.js app to a container registry.


How to Push a Dockerized Node.js App to a Container Registry was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Randil Tennakoon


Print Share Comment Cite Upload Translate Updates
APA

Randil Tennakoon | Sciencx (2021-12-31T15:18:51+00:00) How to Push a Dockerized Node.js App to a Container Registry. Retrieved from https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/

MLA
" » How to Push a Dockerized Node.js App to a Container Registry." Randil Tennakoon | Sciencx - Friday December 31, 2021, https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/
HARVARD
Randil Tennakoon | Sciencx Friday December 31, 2021 » How to Push a Dockerized Node.js App to a Container Registry., viewed ,<https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/>
VANCOUVER
Randil Tennakoon | Sciencx - » How to Push a Dockerized Node.js App to a Container Registry. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/
CHICAGO
" » How to Push a Dockerized Node.js App to a Container Registry." Randil Tennakoon | Sciencx - Accessed . https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/
IEEE
" » How to Push a Dockerized Node.js App to a Container Registry." Randil Tennakoon | Sciencx [Online]. Available: https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/. [Accessed: ]
rf:citation
» How to Push a Dockerized Node.js App to a Container Registry | Randil Tennakoon | Sciencx | https://www.scien.cx/2021/12/31/how-to-push-a-dockerized-node-js-app-to-a-container-registry/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.