- 开启 docker的api进程
# 假设docker服务器 192.168.79.130
# 编辑
vim /lib/systemd/system/docker.service
#修改ExecStart
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
# 重启守护进程
systemctl daemon-reload
# 重启服务
service docker restart
# 测试是否配置成功
curl 192.168.79.130:2375/version
- 修改maven配置文件settings.xml
<server>
<id>docker-hub</id>
<username>DockerHub账号</username>
<password>DockerHub密码</password>
<configuration>
<email>DockerHub注册邮箱</email>
</configuration>
</server>
- springboot项目,修改pom.xml添加docker-maven-plugin插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>
com.lxzp.CrmHdApplication
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.12</version>
<configuration>
<!-- 要和 settings.xml 中配置的 serviceId 一致-->
<serverId>docker-hub</serverId>
<dockerHost>http://192.168.79.130:2375</dockerHost>
<!-- 镜像名称 -->
<imageName>DockerHub账号/${project.artifactId}</imageName>
<!-- 镜像标签 -->
<imageTags>
<imageTag>dev</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<!-- 相当于 ‘FROM ascdc/jdk8’ -->
<baseImage>ascdc/jdk8</baseImage>
<!-- 覆盖已经存在的镜像 -->
<forceTags>true</forceTags>
<!-- 镜像启动命令 -->
<entryPoint>
["java", "-jar", "/${project.build.finalName}.jar"]
</entryPoint>
<!-- 相当于 ‘ADD target/*.jar /crm_hd-0.0.1-SNAPSHOT.jar’ -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
-
docker-maven-plugin使用
-
启动镜像
# 进入服务器
ssh root@192.168.79.130
# 登录dockerHub
docker login -u 用户名 -p 密码
# 启动
docker run -p 9000:9000 xiwenlu/crm_hd:latest
- 远程访问
http://192.168.79.130:9000
- 大功告成