1. 修改宿主机的docker配置,让其可以远程访问

    vi /lib/systemd/system/docker.service
    

    其中ExecStart=后添加配置 ‐H tcp://0.0.0.0:2375 ‐H unix:///var/run/docker.sock
    在这里插入图片描述

  2. 刷新配置,重启服务

    systemctl daemon‐reload
    systemctl restart docker
    docker start registry
    
  3. 修改项目pom文件

    <build>
        <finalName>app</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring‐boot‐maven‐plugin</artifactId>
            </plugin>
            <!‐‐ docker的maven插件,官网:https://github.com/spotify/docker‐maven‐plugin ‐‐>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker‐maven‐plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <imageName>192.168.184.135:5000/${project.artifactId}:${project.version}
                    </imageName>
                    <baseImage>jdk1.8</baseImage>
                    <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>
                    <dockerHost>http://192.168.184.135:2375</dockerHost>
                </configuration>
            </plugin>
        </plugins>
    </build>
  1. 运行maven命令
mvn clean package docker:build ‐DpushImage
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐