创建容器时没有为 属性 'imageId' 指定值

No value has been specified for property 'imageId' while creating container

我是 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 就像一个魅力。这是他们官方 github 网站中的 bug created and answered