spring - 使用Gradle将Docker镜像推送到dockerhub时​​出错

标签 spring gradle docker spring-boot

我正在使用Gradle尝试此Spring boot with docket example,但是在运行任务gradle build buildDocker时遇到以下错误

C:\Users\zeeshan\Workspace\MyWorkspace\SpringBootDocker>gradle build buildDocker
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
:buildDocker FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildDocker'.
> java.io.IOException: Cannot run program "docker": CreateProcess error=2, The system cannot find the file specified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.092 secs

Docketfile存在于Windows计算机的src \ main \ docker中。

我的 build.gradle 文件:
buildscript {
    repositories {
        maven { url "${nexusUrl}/content/groups/public" }
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

group = 'mydockergroup'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'docker'

jar {
    baseName = 'gs-spring-boot-docker'
    version =  '0.1.0'
}

repositories {
    maven { url "${nexusUrl}/content/groups/public" }
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

task buildDocker(type: Docker, dependsOn: build) {
  push = true
  applicationName = jar.baseName
  dockerfile = file('src/main/docker/Dockerfile')
  doFirst {
    copy {
      from jar
      into stageDir
    }
  }
}

注:我在Ubuntu系统中复制了我的工作区,并且工作正常。在Windows系统的build.gradle中为dockerfile设置文件路径是否存在问题?

最佳答案

我们在docker-maven-plugin中指定dockerDirectory。我认为您可能需要在gradle中设置类似的设置。

<dockerDirectory>${basedir}/docker</dockerDirectory>

关于spring - 使用Gradle将Docker镜像推送到dockerhub时​​出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38263585/

相关文章:

java - 为 Spring 单元测试注入(inject)模拟 @Service

java - 使用 Spring Email 发送电子邮件

gradle - 使用 gradle 构建使用 stanford-corenlp 作为依赖项的 jar 文件时出错

android - 禁用即时运行时,Gradle 构建失败并显示 "Could not read path"

variables - 如何在 Dockerfile 中定义变量?

使用主机网络部署 Docker 堆栈仍然无法正常工作

docker - 如何让prometheus在Docker中与grafana协同工作?

spring - Spring 和 Velocity 的 i18n(国际化)问题

spring - 使用 Spring Cloud 配置运行多实例微服务

gradle - 无法执行从gradle构建的jar文件(包含依赖项)