Gradle Docker插件连接超时

时间:2016-02-27 09:06:53

标签: gradle build docker

我正在尝试使用bmuschko/gradle-docker-plugin创建和构建图像。 Dockerfile已创建,但我似乎无法从中构建映像。我在Centos 7上。

创建Dockerfile:

task createBaseImage(type: Dockerfile) {
    destFile = project.file('docker/base/Dockerfile')
    from 'java:8'
    runCommand 'apt-get update'
    runCommand 'apt-get -qq -y install python3 python3-dev python3-pip'
}

构建图像:

task buildBaseImage(type: DockerBuildImage) {
    dependsOn createBaseImage
    inputDir = createBaseImage.destFile.parentFile
    tag = 'the/tag'
}

运行buildBaseImage任务./gradlew buildBaseImage --info时,执行会挂起并最终失败并显示:

org.apache.http.conn.ConnectTimeoutException: Connect to 192.168.59.103:2376 [/192.168.59.103] failed: Connection timed out

我怀疑我的docker闭包有问题,这是从示例中复制的:

docker {
    url = 'http://192.168.59.103:2376'

    registryCredentials {
        url = 'https://index.docker.io/v1'
        username = '${docker_user}'
        password = '${docker_password}'
        email = 'email@example.com'
    }
}

我尝试了不同的网址,端口等,但问题仍然存在。关于是什么导致这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

使用a different Gradle plugin解决了这个问题。图像可以以类似和简单的方式构建:

task buildBaseImage(type: Docker) {
    baseImage 'java:8'
    applicationName = "app-name"
    tagVersion = 'latest'

    runCommand "apt-get update"
    runCommand "apt-get -qq -y install python3 python3-dev python3-pip"
}

然后通过以下方式推送到Docker Hub:

task pushBaseImage(type: Exec, dependsOn: 'buildBaseImage') {
    executable 'docker'
    args = ['push','-f', getGroup() + '/my-base']
}

使用force跳过推送确认。

  

docker push --help

     

-f, - force = false无需确认即可推送到公共注册表

这是解决连接问题的方法。

这是必需的配置:

apply plugin: 'docker'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'se.transmode.gradle:gradle-docker:1.2'
    }
}

group = "myGroup"

docker {
    maintainer 'Maintainer "maintainer@example.com"'
}