用Docker搭建Nexus私服
- 搜索Nexus
- 在docker容器中加載Nexus鏡像
- 發布本地項目到Nexus私服
- 配置連接方式
- 發布指令
- 打源碼包上傳插件
?
搜索Nexus
??在我們打算使用Nexus時,我們先搜索一下docker景象倉庫中現成的Nexus鏡像。
docker search nexus- 1
其展示的結果如下:
[root@localhost ~]# docker search nexus INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/sonatype/nexus Sonatype Nexus 379 [OK] docker.io docker.io/sonatype/nexus3 Sonatype Nexus Repository Manager 3 337 docker.io docker.io/sonatype/docker-nexus3 Sonatype Nexus 3 [DEPRECATED] 27 [OK] docker.io docker.io/clearent/nexus 21 docker.io docker.io/baselibrary/nexus ThoughtWorks Docker Image: nexus 7 [OK] docker.io docker.io/accenture/adop-nexus ADOP Nexus 5 [OK] docker.io docker.io/bradbeck/nexus-https Dockerized version of Nexus Repo Manager 3... 5 [OK] docker.io docker.io/frekele/nexus docker run --rm --name nexus -p 8081:8081 ... 4 [OK] docker.io docker.io/shifudao/nexus3 clone from nexus3 image but based from ope... 3 [OK] docker.io docker.io/sonatype/nexus-iq-server Sonatype Nexus IQ Server 3 docker.io docker.io/cavemandaveman/nexus Sonatype Nexus container 2 [OK] docker.io docker.io/fabric8/nexus 2 [OK] docker.io docker.io/madmuffin/nexus3 Sonatype Nexus3 Milestone7 docker image 2 [OK] docker.io docker.io/mcreations/jenkins-with-nexus-support Jenkins image with correct SSL config for ... 1 [OK] docker.io docker.io/openshiftdemos/nexus Sonatype Nexus with JBoss Enterprise repos... 1- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
??在這里,被大家使用頻率越高的版本往往STARS指數越高,排位也就越靠前,這樣,我們直接拉取第一個來使用就可以了。
docker pull docker.io/sonatype/nexus- 1
??如下:
[root@localhost ~]# docker pull docker.io/sonatype/nexus Using default tag: latest Trying to pull repository docker.io/sonatype/nexus ... latest: Pulling from docker.io/sonatype/nexus af4b0a2388c6: Pull complete e2c659f5d884: Pull complete 37f6e458506e: Pull complete b8ce98aa6771: Pull complete 90969e21cd0f: Pull complete Digest: sha256:90f8ec0dadf5fef6bab1269a96f4e71583dadb366dde3cc664c599da5e1421e7 [root@localhost ~]# docker run -d -p 8081:8081 --name nexus docker.io/sonatype/nexus 5f23e18df895901f33a7abf01870984a65257f977e27266d6d319706b6e06719- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
在docker容器中加載Nexus鏡像
??指令如下:
docker run -d -p 8081:8081 --name nexus docker.io/sonatype/nexus- 1
??運行結果:
[root@localhost ~]# docker run -d -p 8081:8081 --name nexus docker.io/sonatype/nexus 5f23e18df895901f33a7abf01870984a65257f977e27266d6d319706b6e06719- 1
- 2
??在Nexus運行時,這可能需要等待一段很短的時間,我們可以通過查看Nexus的日志來了解Nexus的運行情況,其指令如下:
docker logs -f nexus- 1
??當docker運行起來后,我們就可以在瀏覽器中進行訪問了,訪問地址為:
http://192.168.44.128:8081/nexus/#welcome- 1
??其中192.168.44.128為虛擬機所對應的ip地址,大家在這里填寫自己所在的ip地址即可。
??運行的界面如下:
??當看到這里時,這說明我們的Nexus已經正常運行,可以進行使用了。
??如果想查看與Nexus相關的更多docker鏡像信息,可以到這里去查看Nexus的docker鏡像官方文檔。
https://hub.docker.com/r/sonatype/nexus/- 1
??在這里,docker的默認賬號為admin,默認密碼為admin123,直接將其拿來就可以使用了。
發布本地項目到Nexus私服
配置連接方式
??配置Maven的settings.xml
<server><id>user-release</id> <username>admin</username> <password>admin123</password> </server> <server> <id>user-snapshots</id> <username>admin</username> <password>admin123</password> </server>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
??配置項目的pom.xml
<distributionManagement><repository><id>user-release</id> <name>user release resp</name> <url>http://192.168.44.128:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>user-snapshots</id> <name>user snapshots resp</name> <url>http://192.168.44.128:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
??該連接地址在Nexus的頁面中就可以找到,如:
??直接來拿復制粘貼就可以了。
發布指令
??在項目中,運行下列指令將項目發布到私服中
mvn deploy- 1
??或點擊IDEA中的deploy快捷指令
??運行結果:
Downloading from user-snapshots: http:www.255055.cn/ //192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/maven-metadata.xml Uploading to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/linear-table-2.0-20180409.124308-1.jar Uploaded to user-snapshots: http://www.douniu178.com 192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/linear-table-2.0-20180409.124308-1.jar (17 kB at 114 kB/s) Uploading to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/linear-table-2.0-20180409.124308-1.pom Uploaded to user-snapshots: http://www.chuangyed.com 192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/linear-table-2.0-20180409.124308-1.pom (1.8 kB at 30 kB/s) Downloading from user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/maven-metadata.xml Uploading to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/maven-metadata.xml Uploaded to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/2.0-SNAPSHOT/maven-metadata.xml (769 B at 20 kB/s) Uploading to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/maven-metadata.xml Uploaded to user-snapshots: http://192.168.44.128:8081/nexus/content/repositories/snapshots/com/mycompany/linear-table/maven-metadata.xml (283 B at 7.6 kB/s)?
??發布后的結果:
打源碼包上傳插件
??源碼包上傳插件如下,將其添加到項目的pom.xml文件中即可。
<build><plugins><plugin> <!-- 打jar包 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.1</version> <configuration> <excludes> <exclude>**/*.properties</exclude> </excludes> </configuration> </plugin> <plugin> <!-- 打源碼 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1<www.boshenyl.cn /version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar<www.mcyllpt.com/goal> <www.feihuanyule.com /goals> </execution> </executions> </plugin> <www.gouyiflb.cn /plugins> <www.caibaoyule.cn /build>?
??當添加上上述插件后,當我們執行mvn deploy時,我們的項目源碼包也將會一并發布到Nexus私服中
總結
以上是生活随笔為你收集整理的用Docker搭建Nexus私服的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android studio3.1卡顿严
- 下一篇: SpringCloud系列二:Restf