[英]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:
主要是:
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
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.