1. idea 集成docker插件
2.配置docker远程连接端口
vi /usr/lib/systemd/system/docker.service
-H tcp://0.0.0.0:2375
3.重新加载配置文件,并重启docker服务
systemctl daemon-reload
systemctl start docker
4.开放端口
firewall-cmd --zone=public --add-port=2375/tcp --permanent
5.重启防火墙
firewall-cmd --reload
6.curl http://127.0.0.1:2375/info
7.idea 连接远程docker容器
8. 项目结构
9.在src/main目录下创建docker目录,并创建Dockerfile文件
FROM openjdk:8-jdk-alpine
ADD *.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
10.修改pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="src/main/docker" file="target/${project.artifactId}-${project.version}.${project.packaging}"></copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
11.配置docker
12.安装项目
13.连接docker
14.部署镜像
15.这块遇到的坑
发布后发现失败,那是因为docker 内容没有安装jdk
16.安装jdk
docker pull java
opnjdk 也会被自动安装上
17.然后重新发布,遇到数据库连接不上,解决办法修改application.yml
将localhost改为远程的地址即可
18.然后发布