300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > springboot学习(六十七) springboot项目通过gradle-docker-plugin插件构建为doker镜像并推送至镜像私服

springboot学习(六十七) springboot项目通过gradle-docker-plugin插件构建为doker镜像并推送至镜像私服

时间:2023-10-08 03:31:53

相关推荐

springboot学习(六十七) springboot项目通过gradle-docker-plugin插件构建为doker镜像并推送至镜像私服

文章目录

前言1、使用gradle部署springboot项目2、Docker开启远程访问3、安装镜像私服Harbor4、gradle中配置插件

前言

springboot从2.4默认提供了打镜像的gradle插件,但通过此插件没找到能设置基础镜像的方式,参见:/u011943534/article/details/112136459,下面介绍一种通过第三方插件打镜像并推送至镜像私服的方式

1、使用gradle部署springboot项目

2、Docker开启远程访问

参考:/u011943534/article/details/112134818

3、安装镜像私服Harbor

参考:/u011943534/article/details/110918562

4、gradle中配置插件

buildscript中引入插件

buildscript {repositories {……mavenCentral()}dependencies {classpath "com.bmuschko:gradle-docker-plugin:6.7.0"}}

插件官网:https://bmuschko.github.io/gradle-docker-plugin

项目路径下的gradle.properties中添加版本信息:

dockerRemoteAddr=tcp://172.16.10.190:2375dockerRegistryUrl=172.16.10.160:88dockerRegistryUsername=admindockerRegistryPassword=Harbor12345

添加配置:

apply plugin: 'com.bmuschko.docker-remote-api'apply plugin: 'com.bmuschko.docker-spring-boot-application'……dockerCreateDockerfile {instruction 'RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone'environmentVariable 'TimeZone', 'Asia/Shanghai'environmentVariable 'myenv', 'this is my test'}docker {url = "${dockerRemoteAddr}"springBootApplication {baseImage = "${dockerRegistryUrl}/library/oneclick/openjdk:11-jdk-oracle"maintainer = 'newframe'ports = [6001, 8719]images = ["${dockerRegistryUrl}/library/${rootProject.name}/${project.name}:${version}"]jvmArgs = ['-Djava.security.egd=file:/dev/./urandom']mainClassName = "com.iscas.business.product.ProductApp"}registryCredentials {url = "http://${dockerRegistryUrl}"username = "${dockerRegistryUsername}"password = "${dockerRegistryPassword}"}}

com.bmuschko.docker-remote-apicom.bmuschko.docker-spring-boot-application是两个插件,除了这俩,还有一个插件com.bmuschko.docker-java-application

springBootApplication对应springboot的一些配置:

url对应远程docker API地址

registryCredentials对应要推送的远程镜像私服地址和用户名密码。

执行dockerBuildImage命令,构建此工程为Docker镜像,执行dockerPushImage命令,将项目构建为Docker镜像,并推送至远程镜像私服。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。