一、准备工作
安装docker
docker -v
验证docker是否安装
安装 nginx
非必选
二、使用docker搭建npm私有仓库
1. 拉取 Verdaccio 的 docker 镜像
docker pull verdaccio/verdaccio
2.创建verdaccio文件夹
cd /data
mkdir verdaccio
cd verdaccio
mkdir conf #config.yaml和htpasswd存放在这里
mkdir storage #包文件等
cd conf
touch config.yaml
touch htpasswd
3. 配置文件
config.yaml
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/rlidwka/sinopia/tree/master/conf
#
# path to a directory with all packages
storage: ./storage
auth:
htpasswd:
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
max_users: -1
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npm.taobao.org
packages:
'@*/*':
# scoped packages
access: $authenticated
publish: $authenticated
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: $authenticated
# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
listen:
- 0.0.0.0:4873
以上配置为仅授权用户(登录用户)可以访问 packages,且禁用用户注册功能
4.设置文件夹权限
chown -R 10001:65533 /data/verdaccio
5.启动镜像
docker run --name verdaccio -d -v /data/verdaccio/conf:/verdaccio/conf -v /data/verdaccio/storage:/verdaccio/storage -p 4873:4873 verdaccio/verdaccio
6.验证是否npm私有仓库是否部署成功
访问 http://{ip}:4873
7.配置 nginx 反向代理
server {
listen 80;
server_name hostname;
location / {
proxy_pass http://127.0.0.1:4873;
proxy_set_header Host $host;
}
}