美文网首页
docker 发布java工程

docker 发布java工程

作者: devLiao | 来源:发表于2019-12-02 23:05 被阅读0次

首先安装docker
https://www.cnblogs.com/wang-yaz/p/10429899.html

先增加pom.xml文件

            <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.2.0</version>
                <configuration>
                    <!-- 这里是最终生成的docker镜像名称 -->
                    <imageName>spring-boot/git-test</imageName>
                    <!-- 基础镜像,运行一个springboot应用只需要基础的java环境就行 -->
                    <baseImage>java:8</baseImage>
                    <!-- docker启动的时候执行的命令 -->
                    <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>

maven的setting.xml

 <pluginGroups>
        <pluginGroup>com.spotify</pluginGroup>
  </pluginGroups>

构建到docker 镜像

 mvn package docker:build

第一次有点慢,甚至可能失败。
如果失败了是网络问题,先去配置下docker的镜像源,或者使用vpn。(配置过的跳过)
mac 环境 perferences - > daemon 配置一下
centos 环境

vim /etc/docker/daemon.json //修改或新建
{
"registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"],   //地址去阿里云的镜像加速里面有
"live-restore": true
}
docker images 
image.png

启动一下就OK了

 docker run -itd -p 10123:10123 spring-boot/git-test

相关文章

网友评论

      本文标题:docker 发布java工程

      本文链接:https://www.haomeiwen.com/subject/kndqgctx.html