使用gradle将docker镜像推送到dockerhub时​​出错

时间:2016-07-08 09:46:15

标签: 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系统中复制了我的工作区,它工作正常。在我的build.gradle中为Windows系统设置dockerfile的文件路径是否有问题?

1 个答案:

答案 0 :(得分:0)

我们在docker-maven-plugin中指定dockerDirectory。我想你可能需要在gradle中设置类似的东西。

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