简体   繁体   English

如何从Spring Boot jar构建DockerImage

[英]How to build DockerImage from Spring Boot jar

I am trying to build a Docker Image from a simple Spring RESTful web service jar. 我正在尝试从一个简单的Spring RESTful Web服务jar构建Docker映像。

For that I have specified the following Dockerfile: 为此,我指定了以下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"]

I am trying to "Build a Docker Image with Maven" from my IDEA cli like stated in the instructions here 我想从我的想法CLI以“建码头工人形象与Maven”像在说明中规定这里

./mvnw install dockerfile:build

Unfortunately this throws an exception: 不幸的是,这引发了一个异常:

Could not build image: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.io.IOException: Permission denied

Since I don't know how to solve this I tried to build an image from the terminal with docker command: 由于我不知道如何解决此问题,因此我尝试使用docker命令从终端构建映像:

$ docker build nordic/demo

Which created the image but with name and tag as <none> . 创建图像但名称和标记为<none> Read about it from docker documentations but nothing said about that. 从Docker 文档中阅读有关它的内容,但对此没有任何评论。

I am new to Docker so im sure there is some fundamental misunderstanding in how to build the Docker Image. 我是Docker的新手,因此确保在构建Docker Image方面存在一些基本误解。 Mainly: 主要是:

  1. When building from terminal how does Docker know how to name the Image? 从终端构建时,Docker如何知道如何命名映像?
  2. When building with spotify plugin, why/what permissions are required to use the plugin (logging in to dockerhub before the build didn't help)? 使用Spotify插件进行构建时,为何/需要什么权限才能使用该插件(在构建无济于事之前登录dockerhub)?

Thanks for any pointers or explanations! 感谢您的任何指示或解释!

Set the permission in /var/run/docker for your_own_username instead of root using the below example command, then give a try. 使用以下示例命令在/ var / run / docker中为your_own_username而不是root设置权限,然后尝试一下。

sudo chown -R root:your_own_username /var/run/docker sudo chown -R root:您的用户名/ var / run / docker

spring boot docker 春季启动泊坞窗

this link will be helpful to build your docker image with spring boot. 该链接将有助于使用spring boot构建您的docker映像。

<properties>
   <docker.image.prefix>springio</docker.image.prefix>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.3.6</version>
            <configuration>
                <repository>${docker.image.prefix}/${project.artifactId}</repository>
    <buildArgs>
        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

this plugin you to include in your pom, you can change you image name in properties field. 您可以将其包含在pom中的此插件中,可以在属性字段中更改图像名称。

if you are getting permission denied error, you have to run it with sudo command 如果您遇到权限被拒绝的错误,则必须使用sudo命令运行它

When you run command: 运行命令时:

docker build -t demo:1 .

in string 'demo:1' demo is repository name and string after colon '1' is tag of image and dot (.) in the end means current directory is build context where your Dockerfile is residing. 字符串'demo:1'中的demo是repository名称,冒号'1'之后的字符串是image的tag ,最后的点(。)表示当前目录是Dockerfile所在的build context

A repository can have many images and they are uniquely identified by tag. 存储库可以包含许多图像,并且它们由标签唯一标识。 If you run command like this without providing tag: 如果您在不提供标签的情况下运行以下命令:

docker build -t demo .

docker will create new image in demo repository and by default attach tag named 'latest' with image, so image in this case will be demo:latest. docker将在演示存储库中创建新图像,并且默认情况下将名为'latest'的标签附加到图像,因此在这种情况下,图像将为demo:latest。 And repository demo will have 2 images demo:1 and demo:latest. 存储库演示将有2个图像demo:1和demo:latest。 Also tag 'latest' does not mean image is latest it is just name of tag. 同样,标记“最新”并不意味着图像是最新的,而只是标记名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建 jar 并运行 spring 从 cmd 启动 - Build jar and run spring boot from cmd Spring Boot + Gradle:如何构建可执行jar - Spring Boot + Gradle: how to build executable jar Gradle 构建:从 Spring 引导文件中排除资源文件 Jar 文件 - Gradle build: Exclude resources files from Spring Boot Jar file 使用gradle从spring boot 1.5.3构建可执行文件.jar - Build executable .jar from spring boot 1.5.3 with gradle 如何为我的Java应用程序+ mysql创建可安装文件(从maven build spring boot创建的jar) - How to create installable for my java application + mysql (jar created from maven build spring boot) 如何在IntelliJ IDEA中为Spring Boot项目构建jar工件 - How to build the jar artifact for a Spring Boot project in IntelliJ IDEA Teamcity-在构建和部署后如何在服务器上运行spring boot jar? - Teamcity - How to run spring boot jar on server after Build and Deploy? 如何使用 gradle + spring boot 1.5 构建子模块的可执行 jar - How to build executable jar of a submodule with gradle + spring boot 1.5 如何使用Maven插件正确构建Spring Boot far jar? - How to properly build a Spring Boot far jar using maven plugin? 如何在 Intellij Idea 中为 Spring Boot 项目构建 jar 文件? - How to build jar file for Spring Boot project in Intellij Idea?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM