maven docker 插件集成的几个小坑

昨晚看springboot视频的时候,发现可使用docker-maven-plugin这个插件直接build出 docker 镜像到远程服务器上,感受很方便,因而本身也试了一下,可是碰到了几个问题,记录一下。java

1、开启docker远程端口

视频中使用的是centos,然而我是Ubuntu。好吧,其实没啥区别,可是仍是有一点小区别的,,好比文件位置不一样。git

Ubuntu下须要编辑的文件为github

vim /etc/default/docker

在最后一行加上spring

DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:6732"

好,咱们把端口设置为了6732,视频中就讲了这个,多是系统缘由,此时我本地用 Telnet 访问这个端口是不通的。docker

咱们还须要apache

vim /lib/systemd/system/docker.service

增长一行vim

EnvironmentFile=-/etc/default/docker

指定使用咱们刚才编辑的文件centos

而后修改springboot

ExecStart=/usr/bin/dockerd -H fd://

服务器

ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS

其实就是指定使用咱们刚才编辑的参数

好了,此时Telnet 通了。

2、配置pom文件

按照视频中的写法

在properties中增长一行指定远程主机的位置,端口为咱们刚才配置的6732

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <dockerHost>http://x.x.x.x:6732</dockerHost>
    </properties>

而后增长一个plugin

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>     
        <!--  imageName>mavenTest</imageName>  -->                  
        <imageName>java</imageName>
        <baseImage>java</baseImage>
        <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

而后咱们执行 mvn -DskipTests clean package docker:build
好,build成功。

问题来了,按照这样写是没问题的。

可是我忽然想到怎么指定我build出来的image名称呢。而后我就把imageName改成了mavenTest

而后就报错了。。。

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.3:build (default-cli) on project mavenTest: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException: Cannot retry request with a non-repeatable request entity: Connection reset by peer -> [Help 1]

看这个错一脸懵逼,连接出错???刚还不是好的吗。又把名字换成java,又能够了。。因而百度了一下,有的说升级版本成0.4.4就能够了,有的说升级成1.0.0能够,然而,并无什么用。

百度提供的有效信息就这么多了,,

因而去 GitHub上看了下,终于在 issues 中发现这样一个问题,

User could be warned if an illegal image name is specified

I have struggled for some time now with a strange problem, where mvn docker:build failed; amongst the error output, "Connection Reset" was found. I finally figured out what caused the issue: My maven project's artifact ID had upper-case letters in it, and I am using ${myPrefix}/${project.artifactId} as the image name. However, docker seems to not allow upper-case letters for images names.

看起来是我同样的问题,他说他的项目名中有大写字母,,,,,看到这里,恍然大悟,把imageName 改为 ttt 试了下,果真能够。。

最后想说一下,,其实这个错误是不该该犯得,由于视频中讲了image的命名规范

only [a-z0-9-_.]

没仔细看,,浪费一个小时。。

相关文章
相关标签/搜索