设为首页收藏本站
网站公告 | 这是第一条公告
     

 找回密码
 立即注册
缓存时间20 现在时间20 缓存数据 和聪明人交流,和靠谱的人恋爱,和进取的人共事,和幽默的人随行。晚安!

和聪明人交流,和靠谱的人恋爱,和进取的人共事,和幽默的人随行。晚安!

查看: 665|回复: 1

Docker部署verdaccio搭建npm私服的实现

[复制链接]

  离线 

TA的专栏

  • 打卡等级:无名新人
  • 打卡总天数:1
  • 打卡月天数:0
  • 打卡总奖励:14
  • 最近打卡:2024-01-24 22:53:59
等级头衔

等級:晓枫资讯-列兵

在线时间
0 小时

积分成就
威望
0
贡献
23
主题
21
精华
0
金钱
90
积分
46
注册时间
2023-10-2
最后登录
2025-5-31

发表于 2025-2-14 04:27:21 | 显示全部楼层 |阅读模式
目录


  • 一、镜像获取
  • 二、修改配置文件
  • 三、创建容器并运行
  • 四、测试运行
  • 五、使用内网穿透 的 web界面坑

一、镜像获取
  1. # 获取 verdaccio 镜像
  2. docker pull verdaccio/verdaccio
复制代码
二、修改配置文件
  1. cd /wwwroot/opt/docker/verdaccio/conf
  2. vim config.yaml
复制代码
config.yaml 配置文件如下,可以根据自己的需要进行修改
  1. #
  2. # This is the default configuration file. It allows all users to do anything,
  3. # please read carefully the documentation and best practices to
  4. # improve security.
  5. #
  6. # Look here for more config file examples:
  7. # https://github.com/verdaccio/verdaccio/tree/5.x/conf
  8. #
  9. # Read about the best practices
  10. # https://verdaccio.org/docs/best

  11. # path to a directory with all packages
  12. storage: ./storage
  13. # path to a directory with plugins to include
  14. plugins: ./plugins

  15. # https://verdaccio.org/docs/webui
  16. web:
  17.   title: Verdaccio
  18.   # comment out to disable gravatar support
  19.   # gravatar: false
  20.   # by default packages are ordercer ascendant (asc|desc)
  21.   # sort_packages: asc
  22.   # convert your UI to the dark side
  23.   # darkMode: true
  24.   # html_cache: true
  25.   # by default all features are displayed
  26.   # login: true
  27.   # showInfo: true
  28.   # showSettings: true
  29.   # In combination with darkMode you can force specific theme
  30.   # showThemeSwitch: true
  31.   # showFooter: true
  32.   # showSearch: true
  33.   # showRaw: true
  34.   # showDownloadTarball: true
  35.   #  HTML tags injected after manifest <scripts/>
  36.   # scriptsBodyAfter:
  37.   #    - '<script type="text/javascript" src="https://my.company.com/customJS.min.js"></script>'
  38.   #  HTML tags injected before ends </head>
  39.   #  metaScripts:
  40.   #    - '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>'
  41.   #    - '<script type="text/javascript" src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js"></script>'
  42.   #    - '<meta name="robots" content="noindex" />'
  43.   #  HTML tags injected first child at <body/>
  44.   #  bodyBefore:
  45.   #    - '<div id="myId">html before webpack scripts</div>'
  46.   #  Public path for template manifest scripts (only manifest)
  47.   #  publicPath: http://somedomain.org/

  48. # https://verdaccio.org/docs/configuration#authentication
  49. auth:
  50.   htpasswd:
  51.     file: ./htpasswd
  52.     # Maximum amount of users allowed to register, defaults to "+inf".
  53.     # You can set this to -1 to disable registration.
  54.     # max_users: 1000

  55. # https://verdaccio.org/docs/configuration#uplinks
  56. # a list of other known repositories we can talk to
  57. uplinks:
  58.   taobao:                                                                                                   
  59.     url: https://registry.npm.taobao.org/
  60.   npmjs:
  61.     url: https://registry.npmjs.org/
  62.   yarnkg:
  63.     url: https://registry.yarnpkg.com/
  64.   tencent:
  65.     url: https://mirrors.cloud.tencent.com/npm/
  66.   cnpm:
  67.     url: https://r.cnpmjs.org/
  68.   npmMirror:
  69.     url: https://skimdb.npmjs.com/registry/
  70. # Learn how to protect your packages
  71. # https://verdaccio.org/docs/protect-your-dependencies/
  72. # https://verdaccio.org/docs/configuration#packages
  73. packages:
  74.   '@*/*':
  75.     # scoped packages
  76.     access: $all
  77.     publish: $authenticated
  78.     unpublish: $authenticated
  79.     proxy: taobao

  80.   '**':
  81.     # allow all users (including non-authenticated users) to read and
  82.     # publish all packages
  83.     #
  84.     # you can specify usernames/groupnames (depending on your auth plugin)
  85.     # and three keywords: "$all", "$anonymous", "$authenticated"
  86.     access: $all

  87.     # allow all known users to publish/publish packages
  88.     # (anyone can register by default, remember?)
  89.     publish: $authenticated
  90.     unpublish: $authenticated

  91.     # if package is not available locally, proxy requests to 'npmjs' registry
  92.     proxy: taobao

  93. # To improve your security configuration and  avoid dependency confusion
  94. # consider removing the proxy property for private packages
  95. # https://verdaccio.org/docs/best#remove-proxy-to-increase-security-at-private-packages

  96. # https://verdaccio.org/docs/configuration#server
  97. # You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
  98. # A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
  99. # WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
  100. server:
  101.   keepAliveTimeout: 60

  102. # https://verdaccio.org/docs/configuration#offline-publish
  103. # publish:
  104. #   allow_offline: false

  105. # https://verdaccio.org/docs/configuration#url-prefix
  106. # url_prefix: /verdaccio/
  107. # VERDACCIO_PUBLIC_URL='https://somedomain.org';
  108. # url_prefix: '/my_prefix'
  109. # // url -> https://somedomain.org/my_prefix/
  110. # VERDACCIO_PUBLIC_URL='https://somedomain.org';
  111. # url_prefix: '/'
  112. # // url -> https://somedomain.org/
  113. # VERDACCIO_PUBLIC_URL='https://somedomain.org/first_prefix';
  114. # url_prefix: '/second_prefix'
  115. # // url -> https://somedomain.org/second_prefix/'

  116. # https://verdaccio.org/docs/configuration#security
  117. # security:
  118. #   api:
  119. #     legacy: true
  120. #     jwt:
  121. #       sign:
  122. #         expiresIn: 29d
  123. #       verify:
  124. #         someProp: [value]
  125. #    web:
  126. #      sign:
  127. #        expiresIn: 1h # 1 hour by default
  128. #      verify:
  129. #         someProp: [value]

  130. # https://verdaccio.org/docs/configuration#user-rate-limit
  131. # userRateLimit:
  132. #   windowMs: 50000
  133. #   max: 1000

  134. # https://verdaccio.org/docs/configuration#max-body-size
  135. max_body_size: 50mb

  136. # https://verdaccio.org/docs/configuration#listen-port
  137. listen:
  138. - '0.0.0.0:4873'              # listen on all addresses (INADDR_ANY)
  139. # - https://example.org:4873  # if you want to use https
  140. # - "[::1]:4873"                # ipv6
  141. # - unix:/tmp/verdaccio.sock    # unix socket

  142. # The HTTPS configuration is useful if you do not consider use a HTTP Proxy
  143. # https://verdaccio.org/docs/configuration#https
  144. # https:
  145. #   key: ./path/verdaccio-key.pem
  146. #   cert: ./path/verdaccio-cert.pem
  147. #   ca: ./path/verdaccio-csr.pem

  148. # https://verdaccio.org/docs/configuration#proxy
  149. # http_proxy: http://something.local/
  150. # https_proxy: https://something.local/

  151. # https://verdaccio.org/docs/configuration#notifications
  152. notify:
  153.    method: POST
  154.    headers: [{ "Content-Type": "application/json;charset=utf-8" }]
  155.    # 发送消息的webhook
  156.    endpoint: xxx
  157.    content: '{ "msgtype": "text","at": { "isAtAll": true }, "text": {"content":"组件发版通知: {
  158.   
  159.   { name }}{
  160.   
  161.   {#each versions}} v{
  162.   
  163.   {version}}{
  164.   
  165.   {/each}}"}}'

  166. middlewares:
  167.   audit:
  168.     enabled: true

  169. # https://verdaccio.org/docs/logger
  170. # log settings
  171. logs: { type: stdout, format: pretty, level: http }
  172. #experiments:
  173. #  # support for npm token command
  174. #  token: false
  175. #  # disable writing body size to logs, read more on ticket 1912
  176. #  bytesin_off: false
  177. #  # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
  178. #  tarball_url_redirect: 'http://175.42.30.161:46803/verdaccio/${packageName}/${filename}'
  179. #  tarball_url_redirect: 'http://175.42.30.161:46803/${packageName}/${filename}'
  180. #  # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
  181. #  tarball_url_redirect(packageName, filename) {
  182. #    const signedUrl = // generate a signed url
  183. #    return signedUrl;
  184. #  }

  185. # translate your registry, api i18n not available yet
  186. i18n:
  187. # list of the available translations https://github.com/verdaccio/verdaccio/blob/master/packages/plugins/ui-theme/src/i18n/ABOUT_TRANSLATIONS.md
  188.    web: zh-CN
复制代码
  1. auth:
  2.   htpasswd:
  3.     file: ./htpasswd  # 是 npm 私服的用户密码文件

  4. max_body_size: 50mb # 是推上私服的包的最大大小



  5. listen:
  6. - '0.0.0.0:4873'   # 是监听的ip和端口,4873 就是后面访问的端口



  7. notify:
  8.    method: POST
  9.    headers: [{ "Content-Type": "application/json;charset=utf-8" }]
  10.    # 推包后发送消息的 webhook 地址,如没有则不用配置
  11.    endpoint: xxx
复制代码
三、创建容器并运行
  1. docker run -d --name verdaccio \n
  2. -p 4873:4873 \n
  3. -v /wwwroot/opt/docker/verdaccio:/verdaccio \n
  4. --privileged=true verdaccio/verdaccio
复制代码
四、测试运行

此时,verdaccio已经启动,http://ip:4873/ 已经可以访问

五、使用内网穿透 的 web界面坑

在搭建公司私有库时,使用的内网ip,但是为了在外面方便访问,运营将内网ip穿透得到一个外网可以访问的ip。但是不能使用内网ip和外网ip同时访问web页面。查看verdaccio的页面请求发现会将当天第一次请求的域名缓存起来。假设当天先访问内网环境域名,则外网环境web页面将无法访问,因为请求被写死成内网地址,如果先访问外网地址,则内网地址跳转到无包页面。
到此这篇关于Docker部署verdaccio搭建npm私服的实现的文章就介绍到这了,更多相关Docker Verdaccio搭建Npm内容请搜索晓枫资讯以前的文章或继续浏览下面的相关文章希望大家以后多多支持晓枫资讯!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
晓枫资讯-科技资讯社区-免责声明
免责声明:以上内容为本网站转自其它媒体,相关信息仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同其观点或证实其内容的真实性。
      1、注册用户在本社区发表、转载的任何作品仅代表其个人观点,不代表本社区认同其观点。
      2、管理员及版主有权在不事先通知或不经作者准许的情况下删除其在本社区所发表的文章。
      3、本社区的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,举报反馈:点击这里给我发消息进行删除处理。
      4、本社区一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
      5、以上声明内容的最终解释权归《晓枫资讯-科技资讯社区》所有。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~

  离线 

TA的专栏

等级头衔

等級:晓枫资讯-列兵

在线时间
0 小时

积分成就
威望
0
贡献
0
主题
0
精华
0
金钱
20
积分
20
注册时间
2022-12-29
最后登录
2022-12-29

发表于 6 天前 | 显示全部楼层
感谢楼主分享。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~
严禁发布广告,淫秽、色情、赌博、暴力、凶杀、恐怖、间谍及其他违反国家法律法规的内容。!晓枫资讯-社区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1楼
2楼

手机版|晓枫资讯--科技资讯社区 本站已运行

CopyRight © 2022-2025 晓枫资讯--科技资讯社区 ( BBS.yzwlo.com ) . All Rights Reserved .

晓枫资讯--科技资讯社区

本站内容由用户自主分享和转载自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。

如有侵权、违反国家法律政策行为,请联系我们,我们会第一时间及时清除和处理! 举报反馈邮箱:点击这里给我发消息

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表