docker-maven-elipse打包镜像(十三)
cookqq ›博客列表 ›docker+node.js+zookeeper构建微服务

docker-maven-elipse打包镜像(十三)

2018-08-30 14:27:57.0|分类: docker+node.js+zookeeper构建微服务|浏览量: 2025

摘要: eclipse使用maven进行打包镜像,并且上传到本地registry,eclipse怎么知道docker容器的位置呢?开发环境需要设置DOCKER_HOST,DOCKER_HOST指定了docker的ip和端口号

1、添加Dockerfile

资源文件必须要放到src\main\resources


Dockefile内容

FROM java
MAINTAINER "conca"<136641953@qq.com>
ADD @project.build.finalName@.jar app.jar
EXPOSE 8080
CMD java -jar app.jar


2 pom.xml增加插件

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
      <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.10</version>
        <configuration>
          <imageName>${project.groupId}/${project.artifactId}:${project.version}</imageName>
          <dockerDirectory>${project.build.outputDirectory}</dockerDirectory>
          <resources>
            <resource>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}.jar</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>



3、eclipse执行mvn docker:build


blob.png


执行结果报错

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Hello 1.0.0

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- docker-maven-plugin:0.4.10:build (default-cli) @ conca-hello ---

[INFO] No resources will be copied, no files match specified patterns

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\application.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\application.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\Dockerfile -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\Dockerfile

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\MANIFEST.MF -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\MANIFEST.MF

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.xml -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.xml

[INFO] Building image com.cookqq/conca-hello:1.0.0

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 4.443s

[INFO] Finished at: Wed Aug 22 11:14:20 CST 2018

[INFO] Final Memory: 25M/208M

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.10:build (default-cli) on project conca-hello: Exception caught: Request error: POST https://192.168.99.100:2376/build?t=com.cookqq/conca-hello:1.0.0: 400: HTTP 400 Bad Request -> [Help 1]

[ERROR] 

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR] 

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1]

http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


错误分析:请求192.168.99.100:2376链接失败,192.168.99.100:2376是在哪里设置的呢?

blob.png

经过发现ip和端口号都对啊,哪里出现的错误呢?一直在考虑是否是IP和端口号设置错了。

将版本docker-maven-plugin设置成了1.0.0

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
      <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>1.0.0</version>
        <configuration>
          <imageName>${project.groupId}/${project.artifactId}:${project.version}</imageName>
          <dockerDirectory>${project.build.outputDirectory}</dockerDirectory>
          <resources>
            <resource>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}.jar</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

再次执行mvn docker:build,发现错误信息丰富了,突然看懂了一句话

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Hello 1.0.0

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ conca-hello ---

[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]

[INFO] No resources will be copied, no files match specified patterns

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\application.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\application.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\controller\HelloController.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\controller\HelloController.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\HelloApplication.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\HelloApplication.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\RegistryConfig.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\RegistryConfig.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\ServiceRegistry.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\ServiceRegistry.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\ServiceRegistryImpl.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\ServiceRegistryImpl.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\WebListenter.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\WebListenter.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\Dockerfile -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\Dockerfile

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\MANIFEST.MF -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\MANIFEST.MF

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.xml -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.xml

[INFO] Building image com.cookqq/conca-hello:1.0.0

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 4.582s

[INFO] Finished at: Wed Aug 22 12:21:14 CST 2018

[INFO] Final Memory: 26M/214M

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project conca-hello: Exception caught: Request error: POST https://192.168.99.100:2376/build?t=com.cookqq%2Fconca-hello%3A1.0.0: 400, body: {"message":"Dockerfile parse error line 4: EXPOSE requires at least one argument"}: HTTP 400 Bad Request -> [Help 1]

[ERROR] 

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR] 

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


经过检查Dockerfile 发现EXPOSE 8080后面没有写8080端口号


FROM java:8
MAINTAINER "conca"<136641953@qq.com>
ADD @project.build.finalName@.jar app.jar
EXPOSE 8080
CMD java -jar app.jar


执行的时候发现@project.build.finalName@.jar中@project.build.finalName@不能识别是,直接修改成自己的包的名字。


[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Hello 1.0.5

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- docker-maven-plugin:1.0.0:build (default-cli) @ conca-hello ---

[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\conca-hello-1.0.5.jar -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\conca-hello-1.0.5.jar

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\application.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\application.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\controller\HelloController.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\controller\HelloController.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\HelloApplication.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\HelloApplication.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\RegistryConfig.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\RegistryConfig.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\ServiceRegistry.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\ServiceRegistry.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\ServiceRegistryImpl.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\ServiceRegistryImpl.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\com\cookqq\registry\WebListenter.class -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\com\cookqq\registry\WebListenter.class

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\Dockerfile -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\Dockerfile

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\MANIFEST.MF -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\MANIFEST.MF

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.properties -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.properties

[INFO] Copying E:\workhome\workspaceMarsMvn\conca-hello\target\classes\META-INF\maven\com.cookqq\conca-hello\pom.xml -> E:\workhome\workspaceMarsMvn\conca-hello\target\docker\META-INF\maven\com.cookqq\conca-hello\pom.xml

[INFO] Building image 192.168.99.100:50000/com.cookqq/conca-hello:1.0.5

Step 1/5 : FROM java:8


 ---> d23bdf5b1b1b

Step 2/5 : MAINTAINER "conca"<136641953@qq.com>


 ---> Using cache

 ---> 0fffcb4e5688

Step 3/5 : ADD conca-hello-1.0.5.jar app.jar


 ---> Using cache

 ---> fbd91d589783

Step 4/5 : EXPOSE 8080


 ---> Using cache

 ---> f3033611534a

Step 5/5 : CMD java -jar app.jar


 ---> Using cache

 ---> 32cbd219055a

ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}

Successfully built 32cbd219055a

Successfully tagged 192.168.99.100:50000/com.cookqq/conca-hello:1.0.5

[INFO] Built 192.168.99.100:50000/com.cookqq/conca-hello:1.0.5

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 15.711s

[INFO] Finished at: Wed Aug 22 16:09:22 CST 2018

[INFO] Final Memory: 18M/272M

[INFO] ------------------------------------------------------------------------


正确执行完毕,使用docker images检查镜像

blob.png


一键分享文章

分类列表

  • • struts源码分析
  • • flink
  • • struts
  • • redis
  • • kafka
  • • ubuntu
  • • zookeeper
  • • hadoop
  • • activiti
  • • linux
  • • 成长
  • • NIO
  • • 关键词提取
  • • mysql
  • • android studio
  • • zabbix
  • • 云计算
  • • mahout
  • • jmeter
  • • hive
  • • ActiveMQ
  • • lucene
  • • MongoDB
  • • netty
  • • flume
  • • 我遇到的问题
  • • GRUB
  • • nginx
  • • 大家好的文章
  • • android
  • • tomcat
  • • Python
  • • luke
  • • android源码编译
  • • 安全
  • • MPAndroidChart
  • • swing
  • • POI
  • • powerdesigner
  • • jquery
  • • html
  • • java
  • • eclipse
  • • shell
  • • jvm
  • • highcharts
  • • 设计模式
  • • 列式数据库
  • • spring cloud
  • • docker+node.js+zookeeper构建微服务
版权所有 cookqq 感谢访问 支持开源 京ICP备15030920号
CopyRight 2015-2018 cookqq.com All Right Reserved.