Docker初识:安装nexus

Linux系统:

#linux查看版本当前操作系统发行信息以及内核版本
[root@wngpenghao ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
[root@wngpenghao ~]# uname -r
3.10.0-693.17.1.el7.x86_64

Docker版本:

Docker version 17.03.0-ce, build 3a232c8

一、安装

1、查找nexus镜像,选择sonatype/nexus3 进行安装

[root@wngpenghao ~]# docker search nexus3
NAME                                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
sonatype/nexus3                       Sonatype Nexus Repository Manager 3             704
shifudao/nexus3                       clone from nexus3 image but based from ope...   4                    [OK]
madmuffin/nexus3                      Sonatype Nexus3 Milestone7 docker image         2                    [OK]
home1oss/nexus3                       An auto configured nexus3                       2                    [OK]
flavioaiello/nexus3                   Production ready lightweight Nexus3 with A...   1                    [OK]
cirepo/nexus3                         An auto configured nexus3                       1                    [OK]
alvindaiyan/nexus3-azure-appservice                                                   1
fxinnovation/nexus3                   Sonatype Nexus 3 in a container                 1                    [OK]
sdase/nexus3-base-image               An opinionated nexus3 docker image, based ...   0                    [OK]
freckleiot/nexus3-oss                 A Sonatype Nexus3 OSS image which makes it...   0                    [OK]
joshdvir/nexus3                       nexus3                                          0                    [OK]
mritd/nexus3                          nexus3                                          0                    [OK]
lokkju/nexus3-github-auth             Sonatype Nexus 3 with Github authenticatio...   0                    [OK]
stocksoftware/nexus3                  A nexus3 docker instance                        0                    [OK]
azaa1/nexus3                          Sonyatype Nexus Repository Manager 3            0
salte/nexus3                          Extends the Sonatype nexus3 Docker image b...   0                    [OK]
enieuw/nexus3-oss                     nexus3-oss                                      0                    [OK]
desiato/nexus3-ssl                    Sonatype Nexus 3 with SSL/TLS support.          0                    [OK]
dwolla/nexus3-crowd                   Nexus3 with nexus3-crowd-plugin installed       0                    [OK]
jullyannem/nexus3                     Custom image for sonatype/nexus3                0
bigseasre/nexus3                      mirror of the original nexus3 dockerfile        0
darthhater/nexus3                     A series of example Dockerfiles and images...   0                    [OK]
fgbulsoni/nexus3                      My fork of the Sonatype/Nexus3 image, with...   0
amribrahim00/nexus3                                                                   0
nasajon/nexus3                        Nexus3                                          0                    [OK]

2、拉取nexus3镜像

[root@wngpenghao ~]# docker pull docker.io/sonatype/nexus3

3、查看镜像

[root@wngpenghao ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sonatype/nexus3     latest              8eb898be2a53        4 weeks ago         611 MB

4、运行nexus3 

[root@wngpenghao ~]# docker run -id --privileged=true --name=nexus3 -e NEXUS_CONTEXT=nexus3 --restart=always -p 10001:8081 -v /opt/nexus-data:/opt/docker/nexus-data 8eb898be2a53

说明:

-id 创建守护式容器
--privileged=true 授予root权限(挂载多级目录必须为true,否则容器访问宿主机权限不足)
--name=名字 给你的容器起个名字
-p 宿主机端口:10001:8081表示宿主机端口和容器端口映射
-v 宿主机目录:容器目录 目录挂载

-e NEXUS_CONTEXT=nexus3表示在访问Nexus后台web时,需要带上nexus进行访问,如http://ip:10001/nexus3
本地若不存在sonatype/nexus3镜像,则会去下载,下载完毕后直接启动

5、查看


[root@wngpenghao ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
32fa5b0899af        8eb898be2a53        "sh -c ${SONATYPE_..."   2 hours ago         Up About an hour    0.0.0.0:10001->8081/tcp   nexus3

然后就可以通过网址查看nexus了。

6、查询登录密码,修改新密码

使用docker安装的nexus3初始密码不再是admin123。直接登录会提示下图:

需要到/nexus-data/admin.password查看临时密码。

如果不知道在哪里,则

[root@wngpenghao /]# find / -name admin.password
/var/lib/docker/volumes/438ca82bb6a7cd45e1d7a7490f6eb241059e07e58c580709dd0c1a85a4bf9d11/_data/admin.password

使用临时密码登录后,会提示你设置新密码。

OK。

7、使用。

nexus3默认是让游客访问、下载的,我们为了安全着想,需要关闭此功能,配置新的帐号让开发者使用即可。

7.1 关闭匿名访问权限。

7.2、创建角色,分配权限。

只需要仓库的view-maven2的browse(访问)、read(读取权限),需要配置public、releases两个个仓库的读取,访问。

新建用户并选择角色。

7.3、配置

以上配置完毕,可以通过页面或者maven进行上传下载了。

8、maven配置文件

settings.xml配置

<profile>
	<id>all-dzpj-maven</id>
	<repositories>
		<repository>
			<id>nexus</id>
			<url>http://x.x.x.x:10000/nexus3/repository/maven-public/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<url>http://x.x.x.x:10000/nexus3/repository/maven-public/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</pluginRepository>
	</pluginRepositories>
</profile>
</profiles>
	
<server>  
 <id>dzpj</id>  
 <username>dzpj</username>  
 <password>xxxxxxxxx</password>  
</server>

pom.xml配置

<distributionManagement>
    <repository>
      <id>dzpj</id>
      <name>Nexus Release Repository</name>
      <url>http://x.x.x.x:10000/nexus3/repository/maven-releases/</url>
    </repository>
    <relocation>
    </relocation>
    <snapshotRepository>
      <id>dzpj</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://x.x.x.x:10000/nexus3/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

二、遇到的问题

1、Error response from daemon: Conflict. The container name "/nexus3" is already in use by container

[root@wngpenghao ~]# docker run -id --privileged=true --name=nexus3 -e NEXUS_CONTEXT=nexus3 --restart=always -p 10001:8081 -v /opt/nexus-data:/opt/docker/nexus-data 8eb898be2a53
docker: Error response from daemon: Conflict. The container name "/nexus3" is already in use by container 1d217a30b1b8173ee3e1459387c2bd3ef676aef830bafa1cbc17ff16bc34872a. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.

2、如果用的服务器是Linux,注意配置一下安全组策略,否则的话服务访问。

3、上传jar提示,Repository does not allow updating assets: maven-releases。

nexus版本3.X,是与nexus2.X有很大差别。浏览器登录nexus管理界面–>设置图标–>Repository–>Repositories–>maven-releases–>Hosted–>请选择‘Allow redeploy’策略,默认是disable策略,然后保存。 不同版本的nexus,进入的路径可能有差别。
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章