Docker · SpringBoot远程发布

  • 编辑docker配置文件,配置开启端口

vi /usr/lib/systemd/system/docker.service

添加  -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \  

重载配置  
systemctl daemon-reload
重启docker
service docker restart

 

 


  • docker 拉取 java环境

docker pull java


 

  • 软件pom文件配置(两种方法)

方法一:

  

 1        <plugin>
 2                 <groupId>com.spotify</groupId>
 3                 <artifactId>docker-maven-plugin</artifactId>
 4                 <version>1.0.0</version>
 5                 <configuration>
 6                      <!--注意 修改成远程服务器地址-->
 7                      <dockerHost>http://192.168.114.135:2375</dockerHost>
 8                      <imageName>sbt_urban_cloud_reservation</imageName>
 9                      <baseImage>java</baseImage>
10                      <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
11                      <resources>
12                          <resource>
13                              <targetPath>/</targetPath>
14                              <directory>${project.build.directory}</directory>
15                              <include>${project.build.finalName}.jar</include>
16                          </resource>
17                      </resources>
18                 </configuration>
19        </plugin>

 



方法二:

 1、pom文件配置

    

    <plugin>
              <groupId>com.spotify</groupId>
              <artifactId>docker-maven-plugin</artifactId>
              <version>1.0.0</version>
              <configuration>
                     <!--修改成远程服务器地址-->
                     <dockerHost>http://192.168.114.135:2375</dockerHost>
                     <imageName>sbt_urban_cloud_reservation</imageName>
                     <!-- 使用Dockerfile文件发布,指定其路径 -->
                     <dockerDirectory>src/main/docker</dockerDirectory>
                     <resources>
                         <resource>
                             <targetPath>/</targetPath>
                             <directory>${project.build.directory}</directory>
                             <include>${project.build.finalName}.jar</include>
                         </resource>
                     </resources>
                </configuration>
       </plugin>

 

    2、编写Dockerfile文件

     

1 FROM java
2 VOLUME /tmp
3 ADD docker-springboot-0.0.1-SNAPSHOT.jar app.jar
4 RUN bash -c 'touch /app.jar' ENV JAVA_OPTS=""
5 ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

  • 运行maven远程打包命令

 clean package docker:build

 

    

 

posted @ 2018-09-26 19:33  wsyjlly  阅读(1251)  评论(0编辑  收藏  举报