注:gradle-docker-plugin下载比较缓慢,可以从中央仓库下载下来之后传到本地私服
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
}
repositories {
maven {
url = "http://192.168.6.135:8081/nexus/content/groups/public/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath('com.bmuschko:gradle-docker-plugin:6.1.1')
}
}
apply plugin: "com.bmuschko.docker-spring-boot-application"
dependencies {
}
docker {
//如果url不指定的话
// Unix系统默认:unix:///var/run/docker.sock
//Windows系统默认:tcp://127.0.0.1:2375。
url = 'http://10.3.192.39:2375'
registryCredentials {
url = 'http://10.3.192.39:8777'
username = 'admin'
password = 'Harbor12345'
}
springBootApplication {
baseImage = '10.3.192.39:8777/hualongxin/jdk1.8:latest'//指定运行镜像
ports = [8086] //暴露的端口
images = ["10.3.192.39:8777/hualongxin/${project.group}/${project.name}:${version}"]
jvmArgs = ['-Dspring.profiles.active=$env', '-Xmx2048m', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8084']
}
}
运行task dockerPushImage
deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-spring-boot-app
spec:
replicas: 3
selector:
matchLabels:
app: my-spring-boot-app
template:
metadata:
labels:
app: my-spring-boot-app
spec:
containers:
- name: my-spring-boot-app
image: my-spring-boot-app:1.2.3
env:
- name: SPRING_PROFILES_ACTIVE
value: prod