如何永久配置Quarkus使用Nexus仓库并替换quay.io镜像源
Quarkus 配置Nexus镜像仓库相关问题解答
1. 永久配置Quarkus使用Nexus镜像仓库
Quarkus依赖Maven或Gradle的仓库配置,要永久生效需修改构建工具的全局配置:
Maven 用户
- 找到全局
settings.xml文件(路径通常为~/.m2/settings.xml,不存在则新建) - 在
<mirrors>节点下添加Nexus镜像代理配置,覆盖所有仓库请求:
<mirror> <id>nexus-mirror</id> <mirrorOf>*</mirrorOf> <url>http://你的Nexus地址/repository/maven-public/</url> </mirror>
- (可选)在
<profiles>节点添加Nexus仓库配置并激活,确保依赖拉取优先级:
<profile> <id>nexus-profile</id> <repositories> <repository> <id>nexus</id> <url>http://你的Nexus地址/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://你的Nexus地址/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile>
- 在
<activeProfiles>节点激活上述profile:
<activeProfile>nexus-profile</activeProfile>
Gradle 用户
- 全局生效:修改
~/.gradle/init.gradle文件,添加所有项目共用的仓库配置:
allprojects { repositories { maven { url "http://你的Nexus地址/repository/maven-public/" } } }
- 单项目生效:在项目根目录的
build.gradle中替换默认仓库:
repositories { maven { url "http://你的Nexus地址/repository/maven-public/" } }
2. 禁止Quarkus从quay.io下载镜像,改用本地镜像仓库
需分容器镜像构建和Dev Services开发服务两个场景配置:
容器镜像构建场景
使用Jib插件
在application.properties中指定镜像仓库和基础镜像:
quarkus.container-image.registry=你的本地镜像仓库地址 quarkus.jib.base-image=你的本地镜像仓库地址/quay.io/quarkus/quarkus-jvm:latest
或直接在pom.xml的Jib插件配置中修改:
<plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <configuration> <from> <image>你的本地镜像仓库地址/quay.io/quarkus/quarkus-jvm:latest</image> </from> <to> <image>你的本地镜像仓库地址/你的应用镜像名:版本</image> </to> </configuration> </plugin>
使用Docker Buildpacks
在application.properties中指定构建和运行镜像的仓库地址:
quarkus.buildpack.builder-image=你的本地镜像仓库地址/paketobuildpacks/builder:base quarkus.buildpack.run-image=你的本地镜像仓库地址/paketobuildpacks/run:base-cnb
Dev Services开发服务场景
开发时Quarkus自动启动的数据库、MQ等服务,需配置使用本地镜像:
- 在
application.properties全局指定镜像仓库:
quarkus.devservices.image-registry=你的本地镜像仓库地址
- 针对特定服务单独指定镜像(以PostgreSQL为例):
quarkus.datasource.devservices.image-name=你的本地镜像仓库地址/postgres:15
全局Docker代理配置(推荐)
修改Docker守护进程配置/etc/docker/daemon.json(Linux)或对应路径(Mac/Windows),添加Nexus作为Docker镜像代理:
{ "registry-mirrors": ["http://你的Nexus地址/repository/docker-hub/"] }
重启Docker后,所有镜像拉取请求都会自动走Nexus代理,无需单独配置Quarkus。
内容的提问来源于stack exchange,提问作者eerriicc
相关产品推荐
相关产品推荐

