一、搭建私有化npm平台

Verdaccio 是一个简单的、零配置本地私有 npm 软件包代理注册表

1. docker安装Verdaccio

  1. # 查看官方的verdaccio镜像源
  2. docker search verdaccio
  3. # 看到官方镜像源叫 verdaccio/verdaccio,我们下载下来
  4. docker pull verdaccio/verdaccio
  5. # 我们先在我们用户工作目录下,新建一个verdaccio目录 cd ~
  6. # 公司应用挂载盘为 /storage 命令为 cd storage
  7. cd ~
  8. mkdir verdaccio
  9. cd verdaccio
  10. mkdir conf
  11. mkdir storage
  12. mkdir plugins
  13. #进入conf,创建verdaccio需要的配置文件
  14. cd conf
  15. vi config.yaml

2. 配置yaml文件

  1. #
  2. # This is the config file used for the docker images.
  3. # It allows all users to do anything, so don't use it on production systems.
  4. #
  5. # Do not configure host and port under `listen` in this file
  6. # as it will be ignored when using docker.
  7. # see https://github.com/verdaccio/verdaccio/blob/master/wiki/docker.md#docker-and-custom-port-configuration
  8. #
  9. # Look here for more config file examples:
  10. # https://github.com/verdaccio/verdaccio/tree/master/conf
  11. #
  12. # path to a directory with all packages
  13. storage: /verdaccio/storage
  14. auth:
  15. htpasswd:
  16. file: /verdaccio/conf/htpasswd
  17. # Maximum amount of users allowed to register, defaults to "+inf".
  18. # You can set this to -1 to disable registration.
  19. #max_users: 1000
  20. # a list of other known repositories we can talk to
  21. uplinks:
  22. npmjs:
  23. url: https://registry.npmjs.org/
  24. yarn:
  25. url: https://registry.yarnpkg.com/
  26. cnmp:
  27. url: http://r.cnpmjs.org/
  28. taobao:
  29. url: https://registry.npm.taobao.org/
  30. packages:
  31. '@*/*':
  32. # scoped packages
  33. access: $all
  34. publish: $all
  35. proxy: npmjs
  36. '**':
  37. # allow all users (including non-authenticated users) to read and
  38. # publish all packages
  39. #
  40. # you can specify usernames/groupnames (depending on your auth plugin)
  41. # and three keywords: "$all", "$anonymous", "$authenticated"
  42. access: $all
  43. # allow all known users to publish packages
  44. # (anyone can register by default, remember?)
  45. publish: $all
  46. # if package is not available locally, proxy requests to 'npmjs' registry
  47. proxy: npmjs
  48. # To use `npm audit` uncomment the following section
  49. middlewares:
  50. audit:
  51. enabled: true
  52. # log settings
  53. logs:
  54. - {type: stdout, format: pretty, level: trace}
  55. #- {type: file, path: verdaccio.log, level: info}
  56. listen: 0.0.0.0:4873

3. 执行docker命令

  1. # 创建+运行verdaccio容器
  2. docker run \
  3. --name verdaccio \
  4. -d \
  5. -it \
  6. -p 4873:4873 \
  7. -v /storage/verdaccio/conf:/verdaccio/conf \
  8. -v /storage/verdaccio/storage:/verdaccio/storage \
  9. -v /storage/verdaccio/plugins:/verdaccio/plugins \
  10. -v /etc/localtime:/etc/localtime:ro \
  11. verdaccio/verdaccio

二、配置verdaccio

1. 权限

2. 通知

问题

1. 文件权限问题

注意:Verdaccio 在容器内以非 root 用户(uid=10001)运行,如果使用绑定挂载覆盖默认值,则需要确保挂载目录分配给正确的用户。在上面的例子中,你需要运行下面的命令,否则你会在运行时得到权限错误。

  1. // /path/for/verdaccio => /storage/verdaccio (作者自己的目录)
  2. sudo chown -R 10001:65533 /path/for/verdaccio

参考资料