使用docker起一个verdaccio的容器

安装docker镜像

[root@test5 lianxi]# docker pull verdaccio/verdaccio
[root@test5 lianxi]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
<none>                <none>    0849d2c5af48   2 days ago      204MB
verdaccio/verdaccio   latest    120b7a8b71d7   13 days ago     149MB

安装前的配置

因为docker起verdaccio容器的时候,会到config文件夹里面去读取config.yaml,所以我们需要自己在config文件夹下面新建一个config.yaml的文件,并将内容复制粘贴进去

[root@test5 lianxi]# mkdir  ./verdaccio
[root@test5 lianxi]# cd verdaccio
[root@test5 verdaccio]# mkdir config plugins storage
[root@test5 verdaccio]# cd config
[root@test5 config]# vim config.yaml
[root@test5 config]# cat config.yaml
#
#this is the default configuration file. It allows all users to do anything,
# please read carefully the documentation and best practices to
# improve security.
#
# Do not configure host and port under `listen` in this file
# as it will be ignored when using docker.
# see https://verdaccio.org/docs/en/docker#docker-and-custom-port-configuration
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/5.x/conf
#
# Read about the best practices
# https://verdaccio.org/docs/best

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# https://verdaccio.org/docs/webui
web:
  title: Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc
  # convert your UI to the dark side
  # darkMode: true
  # html_cache: true
  # by default all features are displayed
  # login: true
  # showInfo: true
  # showSettings: true
  # In combination with darkMode you can force specific theme
  # showThemeSwitch: true
  # showFooter: true
  # showSearch: true
  # showRaw: true
  # showDownloadTarball: true
  #  HTML tags injected after manifest <scripts/>
  # scriptsBodyAfter:
  #    - '<script type="text/javascript" src="https://my.company.com/customJS.min.js"></script>'
  #  HTML tags injected before ends </head>
  #  metaScripts:
  #    - '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>'
  #    - '<script type="text/javascript" src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js"></script>'
  #    - '<meta name="robots" content="noindex" />'
  #  HTML tags injected first child at <body/>
  #  bodyBefore:
  #    - '<div id="myId">html before webpack scripts</div>'
  #  Public path for template manifest scripts (only manifest)
  #  publicPath: http://somedomain.org/

# https://verdaccio.org/docs/configuration#authentication
auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
    # Maximum amount of users allowed to register, defaults to "+infinity".
    # You can set this to -1 to disable registration.
    # max_users: 1000
    # Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".
    # algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations
    # Rounds number for "bcrypt", will be ignored for other algorithms.
    # rounds: 10

# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/

# Learn how to protect your packages
# https://verdaccio.org/docs/protect-your-dependencies/
# https://verdaccio.org/docs/configuration#packages
packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $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: $all

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

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

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

# https://verdaccio.org/docs/configuration#server
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# 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.
# 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.
server:
  keepAliveTimeout: 60
  # Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer
  # See: https://expressjs.com/en/guide/behind-proxies.html
  # trustProxy: '127.0.0.1'

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

# https://verdaccio.org/docs/configuration#url-prefix
# url_prefix: /verdaccio/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/my_prefix'
# // url -> https://somedomain.org/my_prefix/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/'
# // url -> https://somedomain.org/
# VERDACCIO_PUBLIC_URL='https://somedomain.org/first_prefix';
# url_prefix: '/second_prefix'
# // url -> https://somedomain.org/second_prefix/'

# https://verdaccio.org/docs/configuration#security
# security:
#   api:
#     legacy: true
#     jwt:
#       sign:
#         expiresIn: 29d
#       verify:
#         someProp: [value]
#    web:
#      sign:
#        expiresIn: 1h # 1 hour by default
#      verify:
#         someProp: [value]

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

# https://verdaccio.org/docs/configuration#max-body-size
# max_body_size: 10mb

# https://verdaccio.org/docs/configuration#listen-port
# listen:
# - localhost:4873            # default value
# - http://localhost:4873     # same thing
# - 0.0.0.0:4873              # listen on all addresses (INADDR_ANY)
# - https://example.org:4873  # if you want to use https
# - "[::1]:4873"                # ipv6
# - unix:/tmp/verdaccio.sock    # unix socket

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

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

# https://verdaccio.org/docs/configuration#notifications
# notify:
#   method: POST
#   headers: [{ "Content-Type": "application/json" }]
#   endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
#   content: '{"color":"green","message":"New package published: * {
   
   { name }}*","notify":true,"message_format":"text"}'

middlewares:
  audit:
    enabled: true

# https://verdaccio.org/docs/logger
# log settings
logs: { type: stdout, format: pretty, level: http }
#experiments:
#  # support for npm token command
#  token: false
#  # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
#  tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'
#  # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
#  tarball_url_redirect(packageName, filename) {
#    const signedUrl = // generate a signed url
#    return signedUrl;
#  }

# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/verdaccio/blob/master/packages/plugins/ui-theme/src/i18n/ABOUT_TRANSLATIONS.md
#   web: en-US

文件目录分级如下:

[root@localhost data]# tree /lianxi
/lianxi
├── docker-compose.yml
└── verdaccio
    ├── config
    │   └── config.yaml
    ├── plugins
    └── storage
   

授权,否则会报错 :Verdaccio在容器中以非根用户(uid=10001)的身份运行,要授权,否则会权限错误

[root@test5 config]# cd /lianxi
[root@test5 lianxi]# chown -R 10001:65533 ./verdaccio/storage/    

编写docker-compose.yml文件:

我是将docker-compose.yml文件存放在/lianxi下,注意存放路径,这根yml文件内部的映射有很大关系,不能弄错

[root@test5 lianxi]# vim docker-compose.yml
[root@test5 lianxi]# cat docker-compose.yml
version: '3'
services:
  verdaccio:
    image: verdaccio/verdaccio
    container_name: "verdaccio"
    environment:
      - VERDACCIO_PORT=4873
    ports:
      - "4873:4873"
    volumes:
      - "./verdaccio/storage:/verdaccio/storage"
      - "./verdaccio/config:/verdaccio/conf"
      - "./verdaccio/plugins:/verdaccio/plugins"  
networks:
  node-network:
    driver: bridge

开始安装

[root@test5 lianxi]# docker-compose up -d
WARNING: Some networks were defined but are not used by any service: node-network
WARNING: Found orphan containers (nginx) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Creating verdaccio ... done
[root@test5 lianxi]# docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS                  PORTS                                                                              NAMES
34d9754ae6e9   verdaccio/verdaccio   "uid_entrypoint /bin…"   10 seconds ago   Up 9 seconds            0.0.0.0:4873->4873/tcp, :::4873->4873/tcp                                          verdaccio

进入容器内部查看

[root@test5 lianxi]# docker exec -it verdaccio /bin/bash    #bash进不去,只有sh可以进去
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
[root@test5 lianxi]# docker exec -it verdaccio /bin/sh
~ $ cd /verdaccio/conf/
/verdaccio/conf $ ls
config.yaml
/verdaccio/conf $ 

容器成功起来之后就可以在web界面上访问了,界面如下图所示:

verdaccio的配置文件解读:

 # 所有包的保存路径  
 storage: /verdaccio/storage/data  
 # 插件的保存路径  
 plugins: /verdaccio/plugins  
 
 # 通过web访问  
 web:    
   title: Verdaccio  
   
 # 账号密码文件,初始不存在  
 auth:    
     htpasswd:      
     file: /verdaccio/storage/htpasswd      
     # max_users:1000      
     # 默认1000,允许用户注册数量。为-1时,不能通过 npm adduser 注册,此时可以直接修改 file 文件添加用户。  
     # 本地不存在时,读取仓库的地址  
uplinks:    
    npmjs:      
      url: https://registry.npmjs.org  
      
# 对包的访问操作权限,可以匹配某个具体项目,也可以通配  
# access 访问下载;publish 发布;unpublish 取消发布;  
# proxy 对应着uplinks名称,本地不存在,去unplinks里取  
# $all 表示所有人都可以执行该操作  
# $authenticated 已注册账户可操作  
# $anonymous 匿名用户可操作  
# 还可以明确指定 htpasswd 用户表中的用户,可以配置一个或多个。 
packages:    
  '@*/*':      
    access: $all      
    publish: $authenticated      
    unpublish: $authenticated      
    proxy: npmjs        
  '**':      
    access: $all      
    publish: $authenticated      
    unpublish: $authenticated      
    proxy: npmjs  
    
# 服务器相关  
sever:    
  keepAliveTimeout: 60  
  
middlewares:    
  audit:      
    enabled: true  
    
# 日志设定  
logs: { type: stdout, format: pretty, level: http }

猜你喜欢

转载自blog.csdn.net/weixin_43880061/article/details/127287262