美文网首页
9、CentOS7 MAVEN_Docker插件 直接构建镜像

9、CentOS7 MAVEN_Docker插件 直接构建镜像

作者: LH_0811 | 来源:发表于2019-05-14 08:47 被阅读0次

1、首先把docker的远程调用打开

vi /lib/systemd/system/docker.service

修改文件在
ExecStart=/usr/bin/dockerd
后面添加
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

修改完成后 重启docker 生效

 systemctl restart docker

2、编写hello maven程序
springboot 创建一个web项目 。请求/hello时 返回hello mvn docker
然后修改pom文件 添加上docker插件

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <imageName>192.168.1.193:5000/mvn_hello_${project.version}</imageName>
                    <baseImage>centos7_jdk8</baseImage>
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <!-- copy the service's jar file from target into the root directory of the image -->
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <dockerHost>http://192.168.1.193:2375</dockerHost>
                </configuration>
            </plugin>

3、构建上传到docker私库

idea会在右侧的maven工具栏中 有docker插件的集成命令。
docker build
docker push

也可以使用maven命令 构建并上传到私库

mvn clean package docker:build -DpushImage

相关文章

网友评论

      本文标题:9、CentOS7 MAVEN_Docker插件 直接构建镜像

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