1.在服务中pom中添加插件
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>eureka</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<dockerHost>http://Docker宿主机ip:2375</dockerHost>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
2.添加src/main/docker source folder, 并添加Dockerfile, 内容:
FROM java:8
VOLUME /temp
ADD eureka-service-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8088
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
3.在本地使用 : mvn clean package docker:build -DskipTests
如果你运气够好,上面三步应该就可以在本地构建镜像到服务器上。下面说一下我遇到的各种坑!!!
1)Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project springb: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect ====》这个问题可以通过在pom中配置<dockerHost>http://Docker宿主机ip:2375</dockerHost> 来解决,但是这样做可能会报出下面的错,我就是这样
2) Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project eureka-service: Exception caught: Timeout: GET http://10.61.213.105:2372135/version: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.ConnectTimeoutException: Connect to 10.61.213.105:2375 [/10.61.213.105] failed: connect timed out
==========================下面是解决方案===============================
/usr/lib/systemd/system/docker.service添加属性:
把ExecStart=/usr/bin/dockerd-current 换成 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock,原本的\要保留然后systemctl daemon-reload。重启docker,telnet成功(相信我这里有很多坑),效果图如下:![在这里插入图片描述](https://img-blog.csdnimg.cn/20200219224008611.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zMjgyMjc1OQ==,size_16,color_FFFFFF,t_70)
3)如果上面问题依然存在,需要检查服务器端口有没有对远程连接开放,可能会需要对防火墙做一些操作,这些可以在网上找到一些资料,最后祝大家好运,能用jenkins就别使用这种方式了。。。
)如果
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/weixin_41830501">
<img src="https://profile.csdnimg.cn/8/E/E/3_weixin_41830501" class="avatar_pic" username="weixin_41830501">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/weixin_41830501" data-report-click="{"mod":"popu_379"}" target="_blank">耳东的慢生活</a></span>
</div>
<div class="text"><span>发布了42 篇原创文章</span> · <span>获赞 7</span> · <span>访问量 5万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=weixin_41830501" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>
</article>
1.在服务中pom中添加插件
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<configuration>
<imageName>eureka</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<dockerHost>http://Docker宿主机ip:2375</dockerHost>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
2.添加src/main/docker source folder, 并添加Dockerfile, 内容:
FROM java:8
VOLUME /temp
ADD eureka-service-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8088
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
3.在本地使用 : mvn clean package docker:build -DskipTests
如果你运气够好,上面三步应该就可以在本地构建镜像到服务器上。下面说一下我遇到的各种坑!!!
1)Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project springb: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect ====》这个问题可以通过在pom中配置<dockerHost>http://Docker宿主机ip:2375</dockerHost> 来解决,但是这样做可能会报出下面的错,我就是这样
2) Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project eureka-service: Exception caught: Timeout: GET http://10.61.213.105:2372135/version: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.ConnectTimeoutException: Connect to 10.61.213.105:2375 [/10.61.213.105] failed: connect timed out
==========================下面是解决方案===============================
/usr/lib/systemd/system/docker.service添加属性:
把ExecStart=/usr/bin/dockerd-current 换成 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock,原本的\要保留然后systemctl daemon-reload。重启docker,telnet成功(相信我这里有很多坑),效果图如下:![在这里插入图片描述](https://img-blog.csdnimg.cn/20200219224008611.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zMjgyMjc1OQ==,size_16,color_FFFFFF,t_70)
3)如果上面问题依然存在,需要检查服务器端口有没有对远程连接开放,可能会需要对防火墙做一些操作,这些可以在网上找到一些资料,最后祝大家好运,能用jenkins就别使用这种方式了。。。
)如果
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/weixin_41830501">
<img src="https://profile.csdnimg.cn/8/E/E/3_weixin_41830501" class="avatar_pic" username="weixin_41830501">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/weixin_41830501" data-report-click="{"mod":"popu_379"}" target="_blank">耳东的慢生活</a></span>
</div>
<div class="text"><span>发布了42 篇原创文章</span> · <span>获赞 7</span> · <span>访问量 5万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=weixin_41830501" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>
</article>