GVKun编程网logo

Nexus:一站式私有仓库管理(NuGet、Maven、npm、Docker)(nexus私有仓库搭建)

18

在本文中,我们将详细介绍Nexus:一站式私有仓库管理的各个方面,并为您提供关于NuGet、Maven、npm、Docker的相关解答,同时,我们也将为您带来关于019.nexus搭建docker镜像

在本文中,我们将详细介绍Nexus:一站式私有仓库管理的各个方面,并为您提供关于NuGet、Maven、npm、Docker的相关解答,同时,我们也将为您带来关于019.nexus 搭建 docker 镜像仓库 /maven 仓库、<五>企业级开源仓库nexus3实战应用–使用nexus3配置npm私有仓库、centos 7 安装 docker win10 系统用 maven 构建镜像并推送到 docker 私有仓库、CentOS7下使用SonatypeNexus3搭建Docker私有仓库的有用知识。

本文目录一览:

Nexus:一站式私有仓库管理(NuGet、Maven、npm、Docker)(nexus私有仓库搭建)

Nexus:一站式私有仓库管理(NuGet、Maven、npm、Docker)(nexus私有仓库搭建)

我们在日常开发中经常需要使用到私有仓库,比如 dotNET 中的 NuGet、Java 中的 Maven、前端的 npm,还有 Docker 镜像,每一个私有仓库各自管理,维护起来比较麻烦,而 Nexus 可以将其统一起来。

本文将介绍 Nexus 的安装以及怎样进行 NuGet 、Maven、npm 和 Docker 镜像的管理。

环境

  • Nexus:3.29.2
  • NuGet:5.5.1
  • Maven:3.6.3
  • NPM:6.14.8
  • Docker:19.03.13
  • 操作系统:CentOS 7

安装

可以使用直接在服务器进行安装或者使用 Docker 镜像的方式安装,本文采用 Docker 镜像的方式安装。

1、执行下面的命令进行容器的构建。

docker run -d -p 8081:8081 -p 8082:8082 --name nexus_8081 -v /root/data/nexus:/nexus-data --restart=always sonatype/nexus3
  • 命令中的 -v /root/data/nexus:/nexus-data 是将 Nexus 的数据目录映射到本地;
  • nexus 目录需要给编辑的权限;
  • 8082 端口的映射目的是为了推送 docker 镜像。

2、执行下面命令开放端口。

firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload

3、构建完后,需要等几十秒到几分钟不等,程序有一个初始化的过程,然后访问 http://ip:8081 ,可以出现下图界面:

4、根据弹窗的提示在映射的目录 /root/data/nexus 中找到 admin.password 中的内容就可以正常登录了。

NuGet

1、在 Repositories 功能中创建 NuGet 的私有仓库 NuGetTest , 仓库模板选择 nuget (hosted) 。

2、在 VS2019 中创建一个 NugetTest 的类库项目,在项目上点击右键→打包,在项目的 bin/Debug 目录中会生成 NugetTest.1.0.0.nupkg 文件。

3、点击「admin」→「NuGet API Key」,在该功能界面获取 key ,这个 key 在推送 NuGet 包时需要用到。

4、将 nuget.exe 程序文件也放到 bin/Debug 目录中,然后打开命令行进入到该目录,执行下面命令进行包的推送。

nuget.exe push NugetTest.1.0.0.nupkg dab3d4df-1eec-36e0-9b75-09b5b4b0ac41 -source http://10.211.55.6:8081/repository/NuGetTest

推送成功如下图:

5、在 VS2019 中的 NuGet 包管理器中添加源。

6、在引用时选择添加的 NuGetTest 源,如下图:

Maven

1、在 Repositories 功能中创建 Maven 的私有仓库 MavenTest , 仓库模板选择 maven (hosted),Deployment policy 需要设置为 Allow redeply,否则在推送时会报 400 的错误。

2、在 Maven 的配置文件 /apache-maven-3.6.3/conf/settings.xml 中的 Servers 节点添加 Server 配置,如下:

<server>
  <id>releases</id>
  <username>test</username>
  <password>000000</password>
</server>
  • username 和 password 是在 Nexus 中创建的测试账户;
  • id 需要和 Maven 项目中的 pom.xml  文件中配置的 id 一致。

3、在 IntelliJ IDEA 中创建 Maven 项目 MavenTest,在项目中的 pom.xml 文件中添加如下内容:

<distributionManagement>
    <repository>
        <id>releases</id>
        <name>releases</name>
        <url>http://10.211.55.6:8081/repository/MavenTest/</url>
    </repository>
</distributionManagement>
  • id:和上面的 settings.xml  文件中的 id 一致即可;
  • url:在 Nenux 中创建的 Maven 仓库的地址。

4、因为仓库创建的是 Release 版本的,如果 pom.xml 文件的 version 中包含 SNAPSHOT ,需要删除,否则在推送时会报 400 的错误

5、在 IDEA 工具的 Maven 模块中进行 depoly 。

6、推送成功后,在 Nexus 中可以看到如下内容:

7、创建一个 spring boot 的项目,并修改 pom.xml 文件,在 dependencies 节点添加依赖,并添加 repositories 配置,如下:

<dependencies>
    <dependency>
        <groupId>org.example</groupId>
        <artifactId>MavenTest</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>releases</id>
        <name>releases</name>
        <url>http://10.211.55.6:8081/repository/MavenTest/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

8、在 IDEA 中的 build 模块中进行同步就可以将 maven 包拉取到项目中。

NPM

1、在 Repositories 功能中创建 npm 的私有仓库 NpmTest , 仓库模板选择 npm (hosted),Deployment policy 需要设置为 Allow redeply,否则在推送时会报 400 的错误。

2、使用 vue 创建一个项目 nexus-test 。

3、使用下面命令进行本地注册,后面的地址为创建的 npm 私有库的地址。

npm config set registry http://10.211.55.6:8081/repository/NpmTest/

4、想要将自己的 npm 包推送到私有仓库中,需要先使用下面的命令进行登录。

npm login –registry=http://10.211.55.6:8081/repository/NpmTest/

5、修改 vue 项目根目录中的 package.json 文件,将 private 设置为 false ,版本号 version 根据需要进行修改。

6、在 Nexus 的 Realms 模块进行设置,将 npm Bearer Token Realm 选到右边的 Active 栏中,此处不设置,在推送时会出现 401 的错误

7、执行下面命令进行包的推送:

npm publish --registry=http://10.211.55.6:8081/repository/NpmTest

8、创建一个新的 vue 项目 nexus-test1 来进行私有仓库的使用,先进行仓库地址的注册。

npm config set registry http://10.211.55.6:8081/repository/NpmTest/

9、执行 npm install nexus-test 进行包的安装,安装成功如下图:

Docker

1、在 Repositories 功能中创建 docker 的私有仓库 DockerTest , 仓库模板选择 docker (hosted) 。

  • 勾选 http, 设置端口为 8082 ,此处的端口为创建 Nexus 容器时设置的 8082 端口 ;
  • 勾选允许匿名拉取镜像;
  • 勾选运行客户端通过 API 访问。

2、在 Nexus 的 Realms 模块进行设置,将 Docker Bearer Token Realm 选到右边的 Active 栏中。

3、在 CentOS 7 系统中安装 Docker ,然后再 /etc/docker/ 目录中创建 daemon.json 文件,内容如下:

{
   "insecure-registries": ["10.211.55.6:9999"]
}

4、执行下面命令进行配置的加载。

systemctl daemon-reload
systemctl restart docker

5、在 root 目录中创建 nexus-docker 目录,目录中创建 Dockerfile 文件用来构建一个新的镜像,内容如下:

FROM nginx:latest
COPY . /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx""-g""daemon off;"]

6、执行下面命令进行镜像的构建和推送到服务端。

# 构建镜像
docker build -t nexus-docker .
# 将镜像 tag 成服务端的地址
docker tag nexus-docker-test:latest 10.211.55.6:8082/nexus-docker-test:latest
# 进行登录 
docker login -u test -p 000000 10.211.55.6:8082
# 推送镜像
docker push 10.211.55.6:8082/nexus-docker-test:latest

操作成功如下图所示:

7、使用镜像的时候,只要服务器进行了第三步中的地址注册,就可以使用 docker pull 10.211.55.6:8082/nexus-docker-test:latest 进行镜像拉取。

希望本文对您有所帮助!

本文分享自微信公众号 - dotNET 跨平台(opendotnet)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。

019.nexus 搭建 docker 镜像仓库 /maven 仓库

019.nexus 搭建 docker 镜像仓库 /maven 仓库

一、安装 docker CE

  参考 docker doc

  https://docs.docker.com/install/linux/docker-ce/centos/

 

二、docker 启动 nexus3

# 1.登录docker hub
docker login

# 2.拉取nexus3镜像
docker pull sonatype/nexus3

# 3.查看镜像
docker images

# 4.启动nexus3
docker run -id --name=nexus3 \
--privileged=true \
--restart=always \
-p 8081:8081 \
-p 10000:10000 \
-p 10010:10010 \
-p 10020:10020 \ 
-v /opt/nexus3/nexus-data:/var/nexus-data \
836c51250912

# 将容器的10000 10010 10020端口映射到host机, 这些端口作为后续nexus3创建的docker镜像仓库支持docker访问的端口


# 5.查看nexus3日志
docker logs -f nexus3

 

三、启动 nexus 失败的问题

   如果服务器内存太小导致 nexus 无法启动,可以启用 swap

   https://www.cnblogs.com/wuxie1989/p/5888595.html

   https://www.cnblogs.com/kerrycode/p/5246383.html

   https://www.cnblogs.com/bingyeh/p/5913486.html

 

  

Part one: nexus 搭建 docker 镜像仓库

一、nexus3 创建 docker 镜像仓库及用户、角色

  • 使用默认管理账号密码登录 nexus3 管理界面

  https://www.jianshu.com/p/77af52a75ad8 

  https://segmentfault.com/a/1190000015629878

 

  登录地址: http:// 服务器 ip:8081

 

  • 三种类型的 docker 镜像仓库

  hosted、proxy、group

  

  设置可以被 docker-cli 直接访问的端口(启动 nexus 容器的时候需要将这些端口暴露到 host 机); 

  

 

 

  • 设置角色、创建用户

   创建角色、设置角色的权限;

  

 

  角色可以继承

  

 

  

 

  创建用户,为用户分配角色;

  

 

 

二、通过 docker-cli 使用镜像仓库

  • 设置 docker-daemon 的 insecure-registries

 

# 1.查看docker-daemon配置文件
systemctl status docker.service

# 2.修改配置文件
vi /usr/lib/systemd/system/docker.service

# ExecStart=/usr/bin/dockerd --insecure-registry 47.116.91.161:10000 --insecure-registry 47.116.91.161:10010 --insecure-registry 47.116.91.161:10020   -H fd:// --containerd=/run/containerd/containerd.sock


# 3.重启docker-daemon systemctl daemon-reload # 4.重启docker systemctl restart docker

 

  •  登录到 nexus3 搭建的 docker 镜像仓库

  docker login xxx:xxx:xxx:xxx:10010

 

 

 

Part Two: nexus 搭建 maven 仓库

https://www.cnblogs.com/dreamroute/p/5440419.html

https://blog.csdn.net/ZZY1078689276/article/details/78953011

一、配置 mavensettings.xml

安装完成的 nexus 已经创建了 4 个 maven 仓库

 

 
## 私服的id需要与nexus仓库id保持一致
   <server>
        <id>maven-releases</id>
        <username>admin</username>
        <password>admin123</password>
    </server>

 

 

二、修改项目 pom.xml

## repository的id与ssettings.xml server id 一致
    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>Nexus-Release-Repository</name>
            <url>http://xx.xxx.xx.xxx:8081/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

 

三、maven build... > goals: deploy

 jar 包即可安装到本地仓库即上传到私服

 

四、SNAPSHOT 版本

  • release 正式仓库则是用来保存稳定的发行版本。

    编译打包时如果发现本地已经存在该版本的模块,则不会再去私服下载。

  • snapshot 快照仓库用于保存开发过程中的不稳定版本,

    定义一个组件 / 模块为快照版本,只需要在 pom 文件中在该模块的版本号后加上 -SNAPSHOT 即可 (注意这里必须是大写);

    mvn deploy 时会自动发布到快照版本库中;

    其他工程使用该快照版本的模块如 1.0-SNAPSHOT,即使本地仓库存在该快照版本模块 1.0-SNAPSHOT,maven 仍会自动从私服下载最新的快照版本。

    实际上发布到快照仓库后,Version 为 1.0 - 发布时间。

 

 

<五>企业级开源仓库nexus3实战应用–使用nexus3配置npm私有仓库

<五>企业级开源仓库nexus3实战应用–使用nexus3配置npm私有仓库

一两个星期之前,你如果在我跟前说起私服的事情,我大概会绕着你走,因为我对这个东西真的一窍不通。事实上也正如此,开发同学曾不止一次的跟我说公司的私服版本太旧了,许多新的依赖编译之后不会从远程仓库自动缓存下来,然后每次就需要手动的上传,不方便极了。我听了之后,一方面确实因为各种忙碌没有抽开时间,但另一方面,则是每当打开私服面对着满屏的英文时,我都觉得眼前私服毕竟还能用,就不折腾了。

 

直到偶然一个契机,在网上看到一篇介绍nexus3.x的文章,文章写得也比较清晰,我也有兴致细读下去,就这样,开启了我的nexus3私服之旅。

开始我以为这个只是针对maven私服而存在的工具,后来才发现它所支持的,竟然将运维日常所面临的各种私服都包括了,这就极大的引发了我的钻研兴致,从maven私服的研究开始,一发不可收拾的,就又写出了一个nexus3系列教程,涵盖了安装,配置,maven私服,maven私服从2.x到3.x的迁移,docker私服,npm私服,yum私服,纵观全网络,大概也找不到一个人如此这般的,倾尽所有的,知无不言的,言无不尽的将nexus3作为一个系列写成文章的了。而现在,如果再有人与我说起私服的事情,至少我不会跑了,或许更想停下来了,,,哈哈。这就是付出学习所给人带来的心境上的转化!

前言啰嗦几句,愿您在这个小系列中,学习愉快!

想要查看本系列其他文章:请点此处跳转。

希望正在读这段话的你能够在这个小系列中获得自信以及喜悦!

当我们运行前端项目的时候,常常在解决依赖的时候会加上一个参数npm install --registry=https://registry.npm.taobao.org将源指定为淘宝的源,以期让速度加快起来,事实上这种的确能够让速度变快,但是长久来看,如果想真正的快速敏捷开发部署,搭建企业内部的私服,则会让速度更上一个台阶。

搭建npm私服,我们依旧使用nexus3。

与其他私服一样的,npm私服同样有三种类型:

  • hosted : 本地存储,即同 docker 官方仓库一样提供本地私服功能
  • proxy : 提供代理其他仓库的类型,如 docker 中央仓库
  • group : 组类型,实质作用是组合多个仓库为一个地址

那么就来一个一个创建。

1,创建blob存储。

为其创建一个单独的存储空间。

2,创建hosted类型的npm。

  • Name: 定义一个名称local-npm
  • Storage:Blob store,我们下拉选择前面创建好的专用blob:npm-hub。
  • Hosted:开发环境,我们运行重复发布,因此Delpoyment policy 我们选择Allow redeploy。这个很重要!

3,创建一个proxy类型的npm仓库。

  • Name: proxy-npm
  • Proxy:Remote Storage: 远程仓库地址,这里填写: https://registry.npmjs.org
  • Storage: npm-hub。

其他的均是默认。

整体配置截图如下:

4,创建一个group类型的npm仓库。

  • Name:group-npm
  • Storage:选择专用的blob存储npm-hub。
  • group : 将左边可选的2个仓库,添加到右边的members下。

整体配置截图如下:

这些配置完成之后,就可以使用了。

5,验证使用。

新建一台环境干净的主机,安装好node环境。

首先通过curl 192.168.106.10/a | sh安装好node环境。

然后拷贝一份前端项目的源码。

1,首先获取默认的仓库地址:

  1. [root@moban business_jsdweb]$npm config get registry
  2. https://registry.npmjs.org/

2,配置为私服地址。

从如下截图中查看(其实就是创建的组对外的地址)。

通过如下命令配置:

  1. [root@moban business_jsdweb]$npm config set registry http://192.168.112.214:8081/repository/group-npm/
  2. [root@moban business_jsdweb]$npm config get registry
  3. http://192.168.112.214:8081/repository/group-npm/

现在开始安装,安装之前先看一下组里的内容:

可以看到还是空的。

3,安装编译。

  1. npm install

在编译的过程中,我们已经可以看看组里的变化了:

安装完成,整个过程如下,可以看到一共花费了82秒

  1. [root@moban business_jsdweb]$npm install
  2.  
  3. > uglifyjs-webpack-plugin@0.4.6 postinstall /root/business_jsdweb/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
  4. > node lib/post_install.js
  5.  
  6. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
  7. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  8.  
  9. added 1216 packages from 717 contributors in 82.171s

4,再一次安装编译。

这里再准备一台环境干净的主机,然后进行一次编译安装,看看效果。

编译之前,先将远程地址配置为我们自己的:

  1. [root@7-3 business_jsdweb]$npm config get registry
  2. https://registry.npmjs.org/
  3. [root@7-3 business_jsdweb]$npm config set registry http://192.168.112.214:8081/repository/group-npm/
  4. [root@7-3 business_jsdweb]$npm config get registry
  5. http://192.168.112.214:8081/repository/group-npm/

然后编译,看效果:

  1. [root@7-3 business_jsdweb]$npm install
  2.  
  3. > uglifyjs-webpack-plugin@0.4.6 postinstall /root/business_jsdweb/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
  4. > node lib/post_install.js
  5.  
  6. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
  7. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  8.  
  9. added 1216 packages from 717 contributors in 31.693s

可以看到,同样是全新的环境下,因为第一次已经将依赖从远程缓存到本地私服,那么在第二次安装编译的时候,用时31秒

私服的重要性,以及便捷性,高下立见!

 

centos 7 安装 docker win10 系统用 maven 构建镜像并推送到 docker 私有仓库

centos 7 安装 docker win10 系统用 maven 构建镜像并推送到 docker 私有仓库

安装 Docker

本文介绍 Docker CE 的安装使用。

移除旧的版本:

$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine

安装一些必要的系统工具:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存:

sudo yum makecache fast

安装 Docker-ce:

sudo yum -y install docker-ce

启动 Docker 后台服务

sudo systemctl start docker

搭建私有仓库

docker run -d -p 5000:5000 -restart=always --name registry2 registry:2

配置 docker 远程访问

修改配置文件 /usr/lib/systemd/system/docker.service,配置远程访问。在 ExecStart=/usr/bin/dockerd,加上下面两个参数

-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

配置完如下

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# ExecStart=/usr/bin/dockerd
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

docker 重新读取配置文件,重新启动 docker 服务

systemctl daemon-reload
systemctl restart docker

查看是否开起 docker 守护线程监听

[root@localhost ~]# ps -ef|grep docker
root       4022      1  0 14:46 ?        00:00:26 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

 注意:生产环境最好将这个关掉,或者做好安全的配置

maven 中添加插件

<plugins>
			<plugin>
				<groupId>com.spotify</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.4.13</version>
				<configuration>
					<dockerHost>http://192.168.5.129:2375</dockerHost>
					<imageName>192.168.5.129:5000/${project.build.finalName}:${project.version}</imageName>
					<baseImage>java</baseImage>
					<entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint>
					<exposes>1111</exposes>
					<resources>
						<resource>
							<targetPath>/</targetPath>
							<directory>${project.build.directory}</directory>
							<include>${project.build.finalName}.jar</include>
						</resource>
					</resources>
					<forceTags> true</forceTags>
				</configuration>
			</plugin>
		</plugins>

注意:

  1. 必须配置 dockerHost 标签(除非配置系统环境变量 DOCKER_HOST=tcp://192.168.5.129:2375)否则默认访问的是 127.0.0.1:2375
  2. imageName 标签中不能以 http 或者其他网络协议开头,如果设置 maven 打包时会报错!
  3. [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project eureka-server: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException: Cannot retry request with a non-repeatable request entity: Connection reset by peer: socket write error -> [Help 1]

     

端口 2375 是 docker 守护线程的端口,编译时必须要获取该 docker 一些版本信息

端口 5000 是 registry 私有仓库的访问端口

构建 docker 并推送到私有仓库

执行以下命令

mvn clean package docker:buid

如果是在 IDE 中需要配置

如果出现以下信息表示构建并推送成功

Step 1/4 : FROM java

 ---> d23bdf5b1b1b
Step 2/4 : ADD /eureka-server.jar //

 ---> e899c3aa60e3
Step 3/4 : EXPOSE 1111

 ---> Running in a0231274bdcb
Removing intermediate container a0231274bdcb
 ---> 4a704fe28128
Step 4/4 : ENTRYPOINT ["java","-jar","/eureka-server.jar"]

 ---> Running in e15b46e004d3
Removing intermediate container e15b46e004d3
 ---> 3894be37b2b6
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 3894be37b2b6
Successfully tagged 192.168.5.129:5000/eureka-server:0.0.1-SNAPSHOT

查看私服中的镜像

[root@localhost ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
192.168.5.129:5000/microservice-discover-eureka   0.0.1               09adbef23e0f        About an hour ago   684MB
registry                                                 2                   b2b03e9146e1        6 weeks ago         33.3MB
java                                                     latest              d23bdf5b1b1b        19 months ago       643MB

参考:https://forums.docker.com/t/expose-the-docker-remote-api-on-centos-7/26022

 

 

 

CentOS7下使用SonatypeNexus3搭建Docker私有仓库

CentOS7下使用SonatypeNexus3搭建Docker私有仓库

前置条件:安装docker(如果机器上没有安装的话)

//安装一些必要的系统工具:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

//添加软件源信息:
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

//更新 yum 缓存:
sudo yum makecache fast

//安装 Docker-ce:
sudo yum -y install docker-ce

//启动 Docker 后台服务
sudo systemctl start docker

安装仓储Nexus3

  • 拉取镜像
docker pull sonatype/nexus3
  • 启动容器
docker run -d --name nexus3 --restart=always -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -p 8085:8085 sonatype/nexus3

8081是nexus主端口,其他4个端口为仓储预留的端口,下面的步骤要用到

  • 访问管理界面
http://服务器的IP:8081/
  • 登录
//在docker目录下查找admin.password文件并查看
cat `find /var/lib/docker -name admin.password -print`
//这一串guid就是默认密码
59837f82-508e-400b-85a1-79aa6ca71bca

默认用户名admin,登录之后在弹出的界面设置密码 image

  • 创建仓储

点击齿轮 - Repositories - Create repository

image

填写仓储名称 - 为仓储分配端口8082,其他设置保持默认

image

  • 安全设置

https://help.sonatype.com/repomanager3/formats/docker-registry/authentication

点击Realms - 将Docker Bearer Token Realm双击Active

image

  • docker设置
//编辑docker服务端设置
vim /etc/docker/daemon.json

//将下面内容加到配置文件种
"insecure-registries":["http://yourip:8082"]

//重启docker
service restart docker

//查看设置是否生效
docker info
  • 登录nexus私有仓库
docker login http://your ip:8082
然后按提示输入账号admin和密码

登录成功 image

制作image

//拉取hello-world镜像作为示例
docker pull hello-world
//制作私有镜像
docker tag hello-world yourip:8082/hello-world
//推送到私有服务器
docker push yourip:8082/hello-world

推送成功 image

现在在私有仓库管理界面可以看到这个镜像了 image

以上,nexus还可以管理nuget,maven和其他包,可以作为企业集中资源管理中心。

原文出处:https://www.cnblogs.com/holdengong/p/11468290.html

关于Nexus:一站式私有仓库管理NuGet、Maven、npm、Docker的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于019.nexus 搭建 docker 镜像仓库 /maven 仓库、<五>企业级开源仓库nexus3实战应用–使用nexus3配置npm私有仓库、centos 7 安装 docker win10 系统用 maven 构建镜像并推送到 docker 私有仓库、CentOS7下使用SonatypeNexus3搭建Docker私有仓库等相关内容,可以在本站寻找。

本文标签:

上一篇.NET 5 部署在docker上运行(.net core docker部署)

下一篇asp.net core 自定义 Content-Type(asp.net core 自定义成功页面)