配置环境:
- centos7+docker
centos+docker配置详情写于2021.07.24 - IDEA 2021
开启docker远程连接
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
systemctl daemon-reload
systemctl restart docker
netstat -tulpn
配置IDEA
-
File ——>settings——>Build,Execution,Deployment——>Docker -
点击+ -
添加 如下图 -
找到service(使用的是idea2021版本) -
链接配置好的远程docker -
右键链接或者点击左边菜单栏的绿色小三角 -
如下表示链接成功
验证链接是否生效
在docker服务器上运行hello-world
[root@DESKTOP-CHAI-wsl ~]
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
docker images
[root@DESKTOP-CHAI-wsl ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
切换到IDEA查看链接docker的情况
可以看出远程链接已经生效
配置自动化配置
添加maven插件docker-maven-plugin
添加该插件可能时间比较长请耐心等待
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
<baseImage>java:8</baseImage>
<maintainer>xxxx xxxx@qq.com</maintainer>
<workdir>/ROOT</workdir>
<cmd>["java", "-version"]</cmd>
<entryPoint>["java","-jar","${project.build.finalName}.jar"]</entryPoint>
<dockerHost>http://192.168.0.220:2375</dockerHost>
<resources>
<resource>
<targetPath>/ROOT</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
配置完成后使用maven的package打包命令
打包完成 可以看出多了一个咱们自己的App的镜像 一个java8的镜像
IDEA创建容器
选中应用镜像右键 创建容器 运行后发现容器里面多了一个刚才运行的容器
切换到docker服务器查看
[root@DESKTOP-CHAI-wsl ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
fttoo/luonan/xf latest ad519896ad54 5 minutes ago 735MB
java 8 d23bdf5b1b1b 4 years ago 643MB
[root@DESKTOP-CHAI-wsl ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcd330da4af9 ad519896ad54 "java -jar xf-1.0.1-…" 2 minutes ago Up 2 minutes 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp app-name
至此docker+IDEA的自动化配置就完成了
|