docker搭建nexus3(docker私服+npm私服)

docker搭建nexus3

拉取docker镜像

docker pull sonatype/nexus3

创建目录

mkdir /docker/nexus3
chmod 777 /docker/nexus3

启动nexus3

docker run -d --name nexus3 \
--restart=always \
-p 8081:8081 \
-p 8082:8082 \
-p 8083:8083 \
-p 8084:8084 \
-p 8085:8085 \
-v /docker/nexus3:/nexus-data \
sonatype/nexus3

设置admin密码

登录IP:8081,点击sign in 登录admin账号密码
提示可以在/nexus-data下找到初始密码admin.password

搭建docker私有仓库

step.1 创建仓库

在这里插入图片描述
并配置如下参数
在这里插入图片描述
修改客户端docker配置

vim /etc/docker/daemon.json
 {
    
    
    "insecure-registries": ["192.168.1.8:8082" ]
}

重启docker

systemctl daemon-reload
systemctl restart docker

登录到仓库

docker login -u admin -p admin123 192.168.1.8:8082  #注意这里的端口是配置仓库时选择的端口号

推送镜像

docker tag nginx:latest 192.168.1.8:8082/nginx:0.1
docker push 192.168.1.8:8082/nginx:0.1

拉取镜像

docker pull 192.168.1.8:8082/nginx:0.1

搭建npm私有仓库

发布npm包时如下

npm publish --registry http://192.168.1.8:8081/repository/my-npm/

第一次发布,发现报错了

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2021-11-15T06_34_01_258Z-debug.log

提示需要登录

首先登录到仓库

npm login --registry http://192.168.1.8:8081/repository/my-npm/
# 输入账号、密码、邮箱

登录后,再次发布,报如下错

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

管理员账号登录nexus
检查npm nexus的 Realms设置,把npm Bearer Token Reaim放入Active中,并保存,如下图
在这里插入图片描述
再次发布,发布成功

有时我们需要将登录验证信息保存下来,这时在下面下创建.npmrc配置文件,并把相关权限信息写进去

首先查看一下全局的配置信息

npm config ls -l

“user” config from C:\Users\Administrator.npmrc

可以找到全局的.npmrc信息

registry=http://registry.npm.taobao.org/
home=https://npm.taobao.org
//192.168.1.8:8081/repository/npm-my/:_authToken=NpmToken.23fbf238-5d91-36bd-b010-a12229d95b50

在本项目下创建.npmrc文件,将全局的权限信息复制到本地
如下所示

//192.168.1.8:8081/repository/npm-my/:_authToken=NpmToken.23fbf238-5d91-36bd-b010-a12229d95b50

猜你喜欢

转载自blog.csdn.net/youlinhuanyan/article/details/121331277