我是 docker 的新手,在 gradle 中使用 bmuschko 插件来创建 docker 镜像、容器并运行它。只有 buildImage 任务似乎有效。创建容器时它说
No value has been specified for property 'imageId'
这是我的 gradle 文件片段。
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'com.bmuschko:gradle-docker-plugin:2.6.5'
}
import com.bmuschko.gradle.docker.tasks.container.*
import com.bmuschko.gradle.docker.tasks.image.*
task copyJar(type: Copy) {
dependsOn 'jar'
from 'build/libs/rest-app-0.0.1-SNAPSHOT.jar'
into 'build/docker'
from 'src/main/resources/Dockerfile'
into 'build/docker'
}
task buildImage(type: DockerBuildImage) {
dependsOn 'copyJar'
inputDir = file('build/docker');
url = 'unix:///var/run/docker.sock'
tag = 'rest-app/nci:0.1'
}
task createContainer(type: DockerCreateContainer) {
dependsOn buildImage
containerName = 'my-rest-app'
targetImageId { buildImage.getImageId() }
portBindings = ['8080:8080']
}
task startContainer(type: DockerStartContainer) {
dependsOn createContainer
targetContainerId { createContainer.getContainerId()}
}
build.dependsOn copyJar
build.dependsOn buildImage
build.dependsOn createContainer
这是堆栈跟踪片段。
..... rest-app:check :rest-app:createContainer ID !!!!!!!8cf8fc8d2af9 :rest-app:createContainer FAILED
FAILURE: Build failed with an exception.
What went wrong: A problem was found with the configuration of task ':rest-app:createContainer'.
No value has been specified for property 'imageId'. Try: Run with --info or --debug option to get more log output.
Exception is: org.gradle.api.tasks.TaskValidationException: A problem was found with the configuration of task ':rest-app:createContainer'. at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:55)
谁能告诉我如何解决这个问题?提前致谢。
最佳答案
找到问题了。似乎功能,即 targetImageId(...)
没有按预期工作。所以从 2.6.6 降级到 2.6.5 就像一个魅力。这是 bug created and answered在他们的官方 github 网站上。
关于gradle - 创建容器时没有为属性 'imageId' 指定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35775274/