1.pom.xml添加插件:
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.12</version> <configuration> <!-- 注意imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功 --> <!-- 详见:https://github.com/spotify/docker-maven-plugin Invalid repository name ... only [a-z0-9-_.] are allowed--> <!--<dockerHost>tcp://192.168.99.100:2376</dockerHost>--> <dockerHost>https://192.168.99.100:2376</dockerHost> <dockerCertPath>/Users/kenkou/.docker/machine/machines/default</dockerCertPath> <imageName>zgz:0.0.1</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.设置虚拟机监听,先到VM VitualBox安装目录下执行以下命令:
VBoxManage modifyvm "default" --natpf1 "guestssh,tcp,,2375,,2376"
3.最后还不行的话,则尝试将该目录下的证书文件(仅需要证书,不需要复制目录)
%USER%.dockermachinecerts 复制到 %USER%.docker
4.然后再到工程目录下执行:
mvn clean package docker:build -DskipTests