【问题标题】:Build docker image using Gradle in SpringBoot using Intellij使用 Intellij 在 Spring Boot 中使用 Gradle 构建 docker 映像
【发布时间】:2018-08-26 07:16:12
【问题描述】:

我有以下 dockerfile。

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

这是 build.gradle。

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'docker'



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


group = 'com.pai'
version = '0.0.1-SNAPSHOT'

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

repositories {
    mavenCentral()
}


dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'mysql:mysql-connector-java'
    compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

build.gradle 进程同步成功。 当我运行以下命令时。

sudo ./gradlew build buildDocker

我收到以下错误消息。

Execution failed for task ':buildDocker'.
> Docker execution failed
  Command line [docker push com.pai/pai201808:0.0.1-SNAPSHOT] returned:
  Get https://com.pai/v2/: dial tcp: lookup com.pai on 127.0.1.1:53: no such host

我认为这可能是错误导入或配置的 dockerfile 无效的问题。我该如何解决这个问题?

【问题讨论】:

    标签: docker spring-boot gradle intellij-idea build.gradle


    【解决方案1】:

    Gradle 脚本尝试将 docker 镜像推送到不存在的存储库。你打算这样做吗?如果不是 - 那么只需设置push = false

    如果要将图像推送到某个存储库,则必须对其进行设置。您必须检查将图像推送到所需存储库的插件特定设置。

    更多信息: Creating new repository on Docker Hub, Setting up own registry

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 2017-02-11
      • 1970-01-01
      • 2020-04-13
      • 2017-07-29
      • 2020-11-14
      • 2018-05-22
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多