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,進入的路徑可能有差別。
 

 

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