1.在pom.xml中配置
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker-maven-plugin.version}</version> <configuration> <dockerHost>${dockerHost}</dockerHost> <imageName>${dockerRegistry}/${project.artifactId}:${docker.tag}</imageName> <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
2.为docker服务开通tcp外部访问(开启2375端口)
3.使用 maven clean package docker:build 命令进行推送镜像到docker服务器