【问题标题】:docker image of spring boot applicationSpring Boot 应用程序的 docker 镜像
【发布时间】:2020-03-12 08:08:16
【问题描述】:

我想学习如何使用 Gradle 创建 Spring Boot 应用程序的 Docker 映像,因为它们是我商店的要求。

要开始我已经推荐了https://spring.io/guides/gs/spring-boot-docker/

我按照此处提到的所有步骤进行操作。

我的 Dockerfile 如下所示

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
EXPOSE 8080
ENTRYPOINT ["java","-cp","app:app/lib/*","hello.Application"]

我的 build.gradle 是

buildscript {
    repositories {
        mavenCentral()
     }
     dependencies {
         classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE")
           }
      }

group = 'springio'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.docker'

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

repositories {
   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 unpack(type: Copy) {
    dependsOn bootJar
    from(zipTree(tasks.bootJar.outputs.files.singleFile))
   into("build/dependency")
     }
docker {
    name "${project.group}/${bootJar.baseName}"
    copySpec.from(tasks.unpack.outputs).into("dependency")
    buildArgs(['DEPENDENCY': "dependency"])
 }

但是当我毁了

    $./gradlew build docker

遇到错误

    FAILURE: Build failed with an exception.

    * Where:
       Build file '/root/springboot-Dockerf/gs-spring-boot-docker/initial/build.gradle' line: 16

    * What went wrong:
        A problem occurred evaluating root project 'initial'.
    > Plugin with id 'com.palantir.docker' not found.

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

【问题讨论】:

    标签: spring-boot docker gradle amazon-ec2 microservices


    【解决方案1】:

    尝试使用以下方式

        plugins {
          id "com.palantir.docker" version "0.22.1"
        }
    
        apply plugin: "com.palantir.git-version"
    
        https://plugins.gradle.org/plugin/com.palantir.docker 
    

    尝试点击此链接 .jar file not found when building a Docker container with Palantir Gradle plug-in

    【讨论】:

    • 我试过但失败了> 启动失败:构建文件'/root/springboot-Dockerf/gs-spring-boot-docker/initial/build.gradle':16:只有buildscript {}和其他在 plugins {} 块之前允许使用 plugins {} 脚本块,不允许使用其他语句 请参阅docs.gradle.org/4.6/userguide/plugins.html#sec:plugins_block 了解有关 plugins {} block @ 第 16 行第 5 列的信息。 plugins {
    • 我已经浏览了这些链接并做了一些更改,现在我遇到了错误 * 出了什么问题:任务“:docker”执行失败。 > 进程 'command 'docker'' 以非零退出值 125 结束
    猜你喜欢
    • 2019-07-13
    • 1970-01-01
    • 2021-09-08
    • 2021-11-08
    • 1970-01-01
    • 2020-06-19
    • 2021-02-27
    • 1970-01-01
    • 2018-06-09
    相关资源
    最近更新 更多