本家はこちら
Google製のJavaをdocker化してくれるアプリでSpringBootのデモアプリをDocker化する
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:0.9.8"
}
}
group = 'net.kosasaki.example'
version = '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.cloud.tools.jib'
dependencies {
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compileOnly('org.projectlombok:lombok:1.18.0')
compile 'mysql:mysql-connector-java:6.0.6'
}
jib {
from {
image = 'adoptopenjdk/openjdk8:alpine-slim'
}
to {
image = 'sample/jib-demo-app'
}
container {
jvmFlags = ['-Xms512m', '-Xdebug']
mainClass = 'net.kosasaki.example.WebApplication'
args = []
ports = ['8080/tcp']
useCurrentTimestamp = true
}
}
build.gradleはこんな感じ。
$ ./gradlew jibDockerBuild
docker images
でイメージを確認する
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sample/jib-demo-app latest 891911ccd0de About a minute ago 133MB
イメージ作成できてました。簡単すぎる。
イメージを実行して確認する
$ docker run --rm -it -p 8080:8080 --name jib-demo-app sample/jib-demo-app
Picked up JAVA_TOOL_OPTIONS