本文介绍了当docker-maven插件尝试构建映像时发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Docker容器中运行Jenkins,Jenkins尝试运行我的maven构建。作为构建的一部分,docker maven插件指示它构建一个docker映像。
POM的一部分在下面。
< plugin> ;
< groupId> com.spotify< / groupId>
< artifactId> docker-maven-plugin< / artifactId>
< version> 0.3.8< / version>
< configuration>
< imageName>示例< / imageName>
< baseImage> java:latest< / baseImage>
< skipDockerBuild> false< / skipDockerBuild>
< cmd> [java,-jar,myLogThread-jar-with-dependencies.jar]< / cmd>
< resources>
< resource>
< directory> target /< / directory>
< include> config.properties< / include>
< / resource>
< resource>
< directory> $ {project.build.directory}< / directory>
< include> myLogThread-jar-with-dependencies.jar< / include>
< / resource>
< / resources>
< / configuration>
< / plugin>
maven构建运行,直到它尝试构建映像,此时出现以下错误消息out:
[INFO]构建图像示例
[INFO] I / O异常(java.io.IOException)在{} - > unix:// localhost:80处理请求时被捕获:拒绝
我可以进入正确的目录,Dockerfile就在那里。
我也可以运行 sudo docker build。
,它将构建没有问题的图像。
为什么maven构建失败?对localhost有什么要求:80?注意:我已经将Docker套接字和二进制文件加载到此容器中
div class =h2_lin>解决方案
可以通过在Jenkins中添加 DOCKER_HOST
环境变量来解决。
如下设置Docker守护程序:
[/ etc / sysconfig / docker]
选项= - H tcp://127.0.0.1:4243
Jenkins作业(注入环境变量) :
DOCKER_HOST = tcp://127.0.0.1:4243
I am running Jenkins in a docker container and Jenkins tries to run my maven build. As part of the build, the docker maven plugin instructs it to build a docker image.
That part of the POM is below.
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.3.8</version>
<configuration>
<imageName>example</imageName>
<baseImage>java:latest</baseImage>
<skipDockerBuild>false</skipDockerBuild>
<cmd>["java", "-jar", "myLogThread-jar-with-dependencies.jar"]</cmd>
<resources>
<resource>
<directory>target/</directory>
<include>config.properties</include>
</resource>
<resource>
<directory>${project.build.directory}</directory>
<include>myLogThread-jar-with-dependencies.jar</include>
</resource>
</resources>
</configuration>
</plugin>
The maven build runs until it attempts to build the image, at which point the following error message is spat out:
[INFO] Building image example
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Permission denied
I can go into the correct directory and the Dockerfile is there.
I can also run sudo docker build .
and it will build the image with no issues.
Why is the maven build failing? What request is being made to localhost:80? How can I correct this so that maven can build my image?
Note: I have mounted the docker socket and binary in this container
解决方案
This can be resolved by adding DOCKER_HOST
environment variable in Jenkins.
Setup your docker daemon like this:
[/etc/sysconfig/docker]
OPTIONS="-H tcp://127.0.0.1:4243"
Jenkins Jobs (Inject environment variables):
DOCKER_HOST=tcp://127.0.0.1:4243
这篇关于当docker-maven插件尝试构建映像时发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!