If I use Docker to deploy my own private warehouse, I will probably encounter many pits. This article records the problems I encounter in the process of building and the solutions. The key, of course, is the process of setting up a private warehouse.

1, environmental

CentOS Linux Release 7.6.1810 (Core)

Docker 19.03.8

2. Know/install Verdaccio

know

Verdaccio: A lightweight Node.js private agent registry

Liverpoolfc.tv: verdaccio.org/

The installation

docker pull verdaccio/verdaccio
Copy the code

Ps: The latest version was Verdaccio 5.4.0 when I installed it

3. Create the project structure and documentation

Yml #docker-compose configuration file -plugins-config-config. yaml #verdaccio configuration file -storageCopy the code

Edit the docker-compose configuration file

File warehouse/docker – compose. Yml

Version: '3.4' Services: Verdaccio: image: Verdaccio/Verdaccio container_name: "Verdaccio" networks: - node-network environment: # VERDACCIO_PORT=3005 # VERDACCIO_PORT= "root" ports: # Host and container volumes: - "./storage:/verdaccio/storage" - "./config:/verdaccio/conf" - "./plugins:/verdaccio/plugins" networks: node-network: driver: bridgeCopy the code

Note the following configuration: VERDACCIO_USER_NAME. If it is not configured or configured incorrectly, an error may be reported later (more on that later).

5. Edit the Verdaccio configuration file

File warehouse/config/config. Yaml

storage: /verdaccio/storage auth: htpasswd: file: /verdaccio/conf/htpasswd uplinks: npmjs: url: https://registry.npmjs.org/ server2: url: https://registry.npm.taobao.org/ packages: '@*/*': access: $all publish: $authenticated Proxy: NPMJS server2 '**': # $all publish: $authenticated proxy: npmjs logs: - {type: stdout, format: pretty, level: http} listen: This port must correspond to -0.0.0.0:3005Copy the code

6. Start the container

Run the following command

docker-compose up -d --build
Copy the code

Open the server url: port (3005) in the browser and the following page will appear

If you follow the above configuration, there should be no error. And that’s the end of it. Next comes the testing phase.


All subsequent operations can be performed on the local computer, there is no need to go to the server.

All subsequent operations can be performed on the local computer, there is no need to go to the server.

All subsequent operations can be performed on the local computer, there is no need to go to the server.

7. Switch the NPM agent

Use NRM to do this. Why NRM uses an article juejin.cn/post/684490…

Install the NRM:

npm i -g nrm
Copy the code

Add the agent

NRM add test < your server address :3005>Copy the code

Switch to the added agent

 nrm use test
Copy the code

8. Add warehouse accounts

npm adduser
Copy the code

The default user will be switched to after the new user is added. You can use the command to confirm whether you have switched to the new user. Otherwise, the following operation may cause problems.

npm who am i
Copy the code

After the preceding command is executed, the current NPM user name is entered

9. Release packages

Release the package you’ve already written.

 npm publish
Copy the code

It then asks you to enter your account number, password, and email address. If it goes well, it prompts success.

If the following error occurs:

npm ERR! 500 Internal Server Error

Check whether VERDACCIO_USER_NAME in warehouse/ docker-comemage. yml is the same as the user who logged in to the server.

In addition to inconsistent user permissions, there is another problem that can cause this error: creating a htpasswd folder in the config/ directory

Refresh the repository page after a successful publication to see the published package

10. Installation package

 npm i xxx
Copy the code

Install here if error 403 Forbidden is prompted

That’s warehouse/config/config. The yaml file, the following code wrong configuration

NPM I XXX, NPM publish: access: $all publish: access: $all publish: $authenticated proxy: npmjsCopy the code

This is the end 😬