npm

Verdaccio Private NPM Registry Setup

lamjack

JackLam

Posted on May 7, 2023

Verdaccio Private NPM Registry Setup

This guide will help you set up a private NPM registry using Verdaccio with Docker Compose. It also includes mounting storage and plugins directories and a custom configuration file.

Step 1: Create Docker Compose file

Create a docker-compose.yml file with the following content:

version: "3.9"

services:
  verdaccio:
    image: "verdaccio/verdaccio:5.24"
    container_name: "verdaccio"
    ports:
      - '4873:4873'
    volumes:
      - './verdaccio-storage:/verdaccio/storage'
      - './verdaccio-plugins:/verdaccio/plugins'
      - './verdaccio-config.yaml:/verdaccio/conf/config.yaml'

Enter fullscreen mode Exit fullscreen mode

This configuration sets up a Verdaccio service using the official Verdaccio image (version 5.24). It exposes port 4873 and mounts three directories:

  • verdaccio-storage for storing NPM packages.
  • verdaccio-plugins for storing Verdaccio plugins.
  • verdaccio-config.yaml for providing a custom configuration.

Step 2: Create a configuration file

Begin by initiating the container, then transfer the configuration file from within the container to the host machine. Proceed to modify the file as required.

# In the docker-compose file, comment out the configuration file mount, and then proceed to launch the container.
docker-compose up -d
docker cp verdaccio:/verdaccio/conf/config.yaml ./verdaccio-config.yaml

# Inspect the user ID and group ID utilized by the container.
# The output will resemble the following:
# uid=10001(abc) gid=10001(abc) groups=10001(abc)
docker run --rm -it verdaccio/verdaccio:5.24 id
sudo chown -R 10001:10001 ./verdaccio-storage
sudo chmod -R 770 ./verdaccio-storage

Enter fullscreen mode Exit fullscreen mode

Prior to initiating, kindly adjust the contents of the configuration file to suit your specific requirements, for instance, by updating max_body_size to 100mb. Lastly, delete the comments from the mount configuration file in the docker-compose file, and proceed to restart the startup service by docker-compose up -d.

Step 3: Set up Nginx reverse proxy (Optional)

Create an Nginx configuration file with the following content:

http {
    # ...Other configuration...

    server {
        listen 80;
        server_name [YOUR_DOMAIN];
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2;
        server_name [YOUR_DOMAIN];

        ssl_certificate /path/to/ssl_certificate.crt;
        ssl_certificate_key /path/to/ssl_certificate_key.key;
        # ... Other SSL configuration ...

        location / {
            proxy_pass http://localhost:4873/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_buffering off;
            proxy_http_version 1.1;
        }
    }
}

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
lamjack
JackLam

Posted on May 7, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related