IDEA 使用Docker
首先设置docker 可以远程连接
在docker.service 文件中填写 [Service] ExecStart 后面 添加 -H tcp://0.0.0.0:2375 表示可以远程的连接
vim /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com BindsTo=containerd.service After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity查看 docker 的状态,可以查看docker 的容器状态以及本身的配置信息。
systemctl status docker.service表示已经启动 ,并且可以查看到是否存在这个配置。

如果没有存在这个配置文件 ,需要重新启动docker
systemctl resatrt docker.service
idea 下载docker 插件
在设置里面去找Plugins ,下载docker 的插件

idea 连接docker
在idea 的settings 里面找到docker

可以看到连接成功,在Engine API URL 里面输入你的docker 所在的服务ip 以及刚刚输入的端口。
idea 配置Dockerfile 文件
FROM java:8 ## 依赖的docker 镜像 VOLUME /tmp ## 存放的临时文件夹 ADD target/ruoyi.jar app.jar ## 添加的jar 文件 ENTRYPOINT ["java","-jar","/app.jar"] ## 运行的Java jar 命令<build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 --> </configuration> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.0</version> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <dockerHost>http://sunbird.top:2375</dockerHost> <imageName>javaboy/${project.artifactId}</imageName> <imageTags> <imageTag>${project.version}</imageTag> </imageTags> <forceTags>true</forceTags> <dockerDirectory>${project.basedir}</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build>在maven pom.xml 文件中填写以上的docker 编译文件 然后对用maven 对jar 进行编译 在进行 docker:build ,最后docker:push 上去。

可以通过docker 看到镜像

版权声明:本文为qq_38828776原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。