Having a Docker Container As Your Private NPM Registry — The Easy Way
By: Sibeesh Venu
Tags: Npm Private Registry, NPM, Azure, Azure Container Service, Docker

Setting up a Docker Private NPM Registry

To create the Azure Container Registry, you should have a valid Azure subscription. If you don’t have one, please get one; it will help you follow this piece. Once you get an Azure subscription, you are ready to start.

Creating an Azure Container Registry

With GitHub, we can upload our projects/source codes, do versioning, create branches, and much more. You can consider the Azure Container Registry as a similar service. An Azure Container Registry or ACR is a private Docker registry where you can easily manage all of your Docker container images from the same place. Isn’t that cool? According to Microsoft, you can use Azure Container Registry to:

Store and manage container images across all types of Azure deployments

Use familiar, open-source Docker command-line interface (CLI) tools

Keep container images near deployments to reduce latency and costs

Simplify registry access management with Azure Active Directory

Maintain Windows and Linux container images within a single Docker registry

Once you log in to the Portal, click on the + icon, create a resource, and search for the Container Registry.

Search Container Registry

When you click the Container Registry, you will be asked to give the details shown in the preceding image.

Container Registry Details

Remember to enable the Admin user, as you will be able to use the registry name as the username and the admin user access key as the password to login to Docker only if it is enabled. I will explain this further in the coming section.

Once you create your Container Registry, you will be given a login server as yourregistryname.azurecr.io . You can always view other information in the overview section. If you click on the Access Keys link under the settings, you can see the username and the password for your Container Registry. Remember, we have enabled the Admin User property while creating the Container Registry.

Container Registry Settings

Note that the registry name and the admin username are the same.

Creating a local Docker Container

For this step, you should download and install Docker on your machine. Once it is installed, please make sure that it is running in your machine. Let’s go ahead and start some amazing things together.

Let’s try the Docker version command first to make sure that it is working correctly.

Docker version

Now that Docker is working fine, we can start creating our local NPM registry. To do so I am going to pull a package from Docker hub, Verdaccio.

Verdaccio is a private npm proxy registry built on top of Node.js. According to the Verdaccio documentation:

It’s a web app based on Node.js

It’s a private npm registry

It’s a local network proxy

It’s a Pluggable application

It’s a fairly easy install and use

It is 100% compatible with yarn, npm, and pnpm

It was forked based on and sinopia@1.4.0 100% backward compatible.

Let’s pull the image of Verdaccio:

docker pull verdaccio/verdaccio

Once you have done that, run “docker images” to see your Verdaccio image.

verdaccio/verdaccio latest c542d9e516e4 3 weeks ago 659MB

It may take a few minutes to pull the entire image. As I have already pulled the latest image, it will be quick for me to get the output below.

Docker pull Verdaccio

You can also tag the version you need:

docker pull verdaccio/verdaccio:3

Now it is time to run the Verdaccio, are you ready?

docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio

The last argument is our image name, if you don’t have such an image in your local files, it will be pulled from Docker hub. As you might have noticed already, we are using port 4873, and the same will be mapped to the container instance port later when we create the container instance. Make sure that you are getting the output shown.

Verdaccio docker run

You should now be able to go to http://localhost:4873 and see that Verdaccio is running successfully.

Pushing our local container to Azure Container Registry

Now that we have an Azure Container Registry running and a local container which can act as a private NPM registry, let’s push this to our ACR. Start by logging to your Azure Container Registry server.

docker login sibeeshpassion.azurecr.io

Once you run the above command with the correct credentials you will see the output below.

Docker login to Azure Container Registry

Now let’s tag our image, as this will help us manage our images easily in the Container Registry.

docker tag <image name> <login server>/<repository name>/<name>:v1

For example, I used the command below:

docker tag verdaccio/verdaccio sibeeshpassion.azurecr.io/verdaccio/verdaccio:v1

Push your image to the Container Registry:

docker push sibeeshpassion.azurecr.io/verdaccio/verdaccio:v1

If everything works correctly, you will see this output:

Pushing to Container Registry

Now, you can log in to your Azure portal and check the repositories of your Azure Container Registry. You should be able to see your image with the tag we have provided.

Repository in Azure Container Registry

Creating a container instance

We have a valid container registry which can act as a private NPM registry, but we are not finished yet. We need a place where this registry can run. Thankfully, Azure has everything we need. We are going to create a Container Instance, which is the simplest and fastest way to run a single container. While creating the Container Instance, you will have to go through three steps:

Configure the basic settings Specify the container requirements Finalize the Container Instance

Configure basic settings

You can configure the settings to suit your needs, I have configured mine as below:

Container Instance Basic Settings

Note that I have set the container image type to Private.

Specify container requirements

Here, I set the Public IP address to “Yes”, so that I can set the DNS label while configuring. I also set the port to 4873.

Network Settings in Azure Container Instance

Finalize the Container Instance

In this step, you can verify all of your settings, and in the background, Azure will validate them. If they are valid, the OK button will be enabled. Click OK once it is enabled. It may take some time to build your resource, once it is done you can always go to the overview of your Container Instance and run it with the port 4873. For example, I can see my container in this URL http://sibeeshpassion.westeurope.azurecontainer.io:4873/#/.

Pushing your own private NPM package to the Docker private NPM registry

Wow, we have a private Docker NPM registry now! Let’s push our private NPM package to this registry. I created my own NPM package a few days back, if you want to know how, you can read this article. I will open my package in vscode.

Before we publish the package, add the user:

npm adduser --registry=http://sibeeshpassion.westeurope.azurecontainer.io:4873/#/

You will be prompted for the username and password:

NPM Publish with Private Registry AddUser

Run our publish command:

npm publish dist --registry=http://sibeeshpassion.westeurope.azurecontainer.io:4873/#/

If the publishing is successful, you will get the following output:

npm notice === Tarball Details ===

npm notice name: org-npm-package

npm notice version: 1.1.1

npm notice package size: 7.8 kB

npm notice unpacked size: 37.9 kB

npm notice shasum: f1d8e033bb6d2545502802510258cf9f8bcc9ab3

npm notice integrity: sha512-3MuplP75D0gpj[...]Z5KFo0DNbzGFw==

npm notice total files: 22

npm notice

+ org-npm-package@1.1.1

What are you waiting for, go and see your package in Docker! I was eagerly waiting for this moment and viewed my package by navigating to my container here: http://sibeeshpassion.westeurope.azurecontainer.io:4873/#/detail/org-npm-package.