1.部署环境
- window 11 x64
- Docker Desktop 4.34.1 (166053)
- Docker Engine v27.2.0
1.1.Docker 镜像源
1.1.1.Docker Engine 配置
{
"builder": {
"features": {
"buildkit": true
},
"gc": {
"defaultKeepStorage": "32GB",
"enabled": true
}
},
"experimental": true,
"hosts": [
"tcp://0.0.0.0:2375"
],
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com"
]
}
2.拉取Nexus3镜像
# 拉取镜像
docker pull sonatype/nexus3
# 保存镜像源(选)
docker save -o sonatype_nexus3_latest sonatype/nexus3:latest
3.创建并运行Nexus3
# 创建运行镜像,设置最大内存
docker run -itd -p 18081:8081 -p 18082:8082 -p 18083:8083 --privileged=true --name nexus3 -v D:\docker\maven\nexus\data:/var/nexus-data -v D:\docker\maven\nexus\nexus-data:/nexus-data -e INSTALL4J_ADD_VM_PARAMS="-Xms512m -Xmx2048m -XX:MaxDirectMemorySize=2048m -Djava.util.prefs.userRoot=/nexus-data/javaprefs" --restart=always docker.io/sonatype/nexus3
说明
- 内存限制
-e INSTALL4J_ADD_VM_PARAMS="-Xms512m -Xmx2048m -XX:MaxDirectMemorySize=2048m -Djava.util.prefs.userRoot=/nexus-data/javaprefs"
--privileged=true
允许容器使用管理员权限--restart=always
自动重启
3.1.访问及查看密码
查看初始登录密码
docker exec -it nexus3 /bin/bash
cat /opt/sonatype/sonatype-work/nexus3/admin.password
修改登录默认密码
访问 http://127.0.0.1:18081/
3.2.创建存储
3.3.创建代理库
参考私库镜像
- aliyun:https://maven.aliyun.com/repository/public
- nexus-aliyun:http://maven.aliyun.com/nexus/content/groups/public
- jeecg:https://maven.jeecg.org/nexus/content/repositories/jeecg
- jeecg-snapshots:https://oss.sonatype.org/content/repositories/snapshots
3.4.创建本地库
3.5.将创建的私库,添加到公共库中
4.配置 maven
可以访问公共库
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>D:\workspace\env\repository</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<server>
<id>xxx-center</id>
<username>admin</username>
<password>xxxxxx</password>
</server>
<server>
<id>xxx-center-snapshot</id>
<username>admin</username>
<password>xxxxxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-public</id>
<mirrorOf>maven-public</mirrorOf>
<name>maven-public</name>
<url>http://xxx.xxx.xxx.xxx:18081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles></profiles>
</settings>
5.配置pom.xml
发布配置
<distributionManagement>
<repository>
<id>xxx-center</id>
<name>xxx-center</name>
<url>http://xxx.xxx.xxx.xxx:18081/repository/djb-center/</url>
</repository>
<snapshotRepository>
<id>djb-center-snapshot</id>
<name>djb-center-snapshot</name>
<url>http://xxx.xxx.xxx.xxx:18081/repository/djb-center-snapshot/</url>
</snapshotRepository>
</distributionManagement>
拉取镜像配置
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://xxx.xxx.xxx.xxx:18081/repository/xxx-center/</url>
</repository>
</repositories>
也可以指定源配置(不推荐)
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun Repository</name>
<url>https://maven.aliyun.com/repository/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jeecg</id>
<name>jeecg Repository</name>
<url>https://maven.jeecg.org/nexus/content/repositories/jeecg</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jeecg-snapshots</id>
<name>jeecg-snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
6.打包与发布
# 打包
mvn -Dfile.encoding=UTF-8 -DskipTests=true clean package -P prod
# 发布
mvn -Dfile.encoding=UTF-8 -DskipTests=true clean deploy -P prod