- 开启docker的远程访问
vim /lib/systemd/system/docker.service
ExecStart=后添加配置 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
- 重启docker守护线程、docker服务、私有仓库
systemctl daemon-reload
systemctl restart docker
docker start registry
-
这里我用的阿里云服务器,需要配置安全组开放端口 2375 项目端口 8080
-
快速创建springboot项目
-
pom配置maven插件
<build>
<finalName>luojiang-demo</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--这里写上main方法所在类的路径-->
<configuration>
<mainClass>com.example.demo.LuojiangDemoApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</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>服务器的ip:5000/${project.artifactId}:${project.version}</imageName>
<!-- 基于**镜像 -->
<baseImage>服务器的ip:5000/docker-demo</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://私服所在服务器ip:2375</dockerHost>
</configuration>
</plugin>
</plugins>
</build>
- 执行构建、推送命令
mvn package docker:build -DpushImage
- 查看私有仓库镜像
- 拉取镜像并启动容器
- 测试外部访问接口