springboot與docker整合

1、springboot與docker整合java

a.建立Dockerfilelinux

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

  報錯:missing :
  解決辦法:修改Dockerfiledocker

  FROM java
  MAINTAINER "Wing"<1561815137@qq.com>
  EXPOSE 8080
  ENTRYPOINT ["java", "-jar", "${project.build.finalName}.jar"]windows

b.項目中pom添加docker plugin
   <docker.registry>172.22.64.45:50000</docker.registry>springboot

具體配置以下:bash

<plugin>
  <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.2.0</version>
    <configuration>
      <imageName>${docker.registry}/${project.groupId}/${project.artifactId}:${project.version}</imageName>
      <dockerDirectory>${project.build.outputDirectory}</dockerDirectory>
      <!-- <dockerHost>http://172.22.64.45:50000</dockerHost>-->
      <resources>
        <resource>
          <targetPath>/</targetPath>
          <directory>
            ${project.build.directory}
          </directory>
          <include>
            ${project.build.finalName}.jar
          </include>
        </resource>
      </resources>
    </configuration>
</plugin>app

c.執行構建命令
  在linux中編譯,在windows編譯有些問題
  mvn package docker:build -Xmaven

d.push鏡像 mvn package docker:build -X -DpushImage
    參考:https://blog.csdn.net/aixiaoyang168/article/details/77453974
               https://blog.csdn.net/fragrant_no1/article/details/84326694ui

e.啓動
    docker run -i -t ef5d1bb3c4bc exec /bin/bash
    <targetPath>/</targetPath>
    EXPOSE 設置可被暴漏的端口號,若是在Dockerfile裏面設置,在外網訪問一直不通
    docker run -d -p 18080:8080 23b670831ef9

相關文章
相關標籤/搜索