一、搭建私有化npm平台
Verdaccio 是一个简单的、零配置本地私有 npm 软件包代理注册表
1. docker安装Verdaccio
# 查看官方的verdaccio镜像源
docker search verdaccio
# 看到官方镜像源叫 verdaccio/verdaccio,我们下载下来
docker pull verdaccio/verdaccio
# 我们先在我们用户工作目录下,新建一个verdaccio目录 cd ~
# 公司应用挂载盘为 /storage 命令为 cd storage
cd ~
mkdir verdaccio
cd verdaccio
mkdir conf
mkdir storage
mkdir plugins
#进入conf,创建verdaccio需要的配置文件
cd conf
vi config.yaml
2. 配置yaml文件
#
# This is the config file used for the docker images.
# It allows all users to do anything, so don't use it on production systems.
#
# Do not configure host and port under `listen` in this file
# as it will be ignored when using docker.
# see https://github.com/verdaccio/verdaccio/blob/master/wiki/docker.md#docker-and-custom-port-configuration
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#
# path to a directory with all packages
storage: /verdaccio/storage
auth:
htpasswd:
file: /verdaccio/conf/htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
#max_users: 1000
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
yarn:
url: https://registry.yarnpkg.com/
cnmp:
url: http://r.cnpmjs.org/
taobao:
url: https://registry.npm.taobao.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $all
proxy: npmjs
'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $all
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# To use `npm audit` uncomment the following section
middlewares:
audit:
enabled: true
# log settings
logs:
- {type: stdout, format: pretty, level: trace}
#- {type: file, path: verdaccio.log, level: info}
listen: 0.0.0.0:4873
3. 执行docker命令
# 创建+运行verdaccio容器
docker run \
--name verdaccio \
-d \
-it \
-p 4873:4873 \
-v /storage/verdaccio/conf:/verdaccio/conf \
-v /storage/verdaccio/storage:/verdaccio/storage \
-v /storage/verdaccio/plugins:/verdaccio/plugins \
-v /etc/localtime:/etc/localtime:ro \
verdaccio/verdaccio
二、配置verdaccio
1. 权限
2. 通知
问题
1. 文件权限问题
注意:Verdaccio 在容器内以非 root 用户(uid=10001)运行,如果使用绑定挂载覆盖默认值,则需要确保挂载目录分配给正确的用户。在上面的例子中,你需要运行下面的命令,否则你会在运行时得到权限错误。
// /path/for/verdaccio => /storage/verdaccio (作者自己的目录)
sudo chown -R 10001:65533 /path/for/verdaccio