idea连接docker实现一键部署的方法

idea连接docker实现一键部署的方法,第1张

idea连接docker实现一键部署的方法

本文主要介绍将idea和docker连接起来实现一键部署的方法。这篇文章很详细的介绍了你,对你的学习或者工作有一定的参考价值。有需要的朋友可以参考一下。

1。修改docker配置文件并打开端口2375

[root@s162docker]#vim/usr/lib/systemd/system/docker.service #查找ExecStart,在末尾添加 #后面加上-Htcp://0.0.0.0:2375 [root@s162docker]#systemctldaemon-reload [root@s162docker]#systemctlstartdocker ##查看2375端口是否启用 [root@s162docker]#lsof-i:2375 COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME dockerd27021root5uIPv63525987990t0TCP*:2375(LISTEN)

2。Idea安装并配置docker插件

2.1.idea-plugins市场安装docker插件。

稍微…

2.2.配置docker

3.3.springboot项目被部署到docker服务器

3.1.写docker/dockerfile

3.2.maven添加docker-maven-plugin插件

<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <!--指定生成的镜像名,如果不指定tag,默认会使用latest--> <imageName>jhs/${project.artifactId}:${project.version}</imageName> <!--添加额外的指定标签,非必须--> <!-- <imageTags> <imageTag>${project.version}</imageTag> </imageTags> --> <!--指定Dockerfile路径:项目根路径下--> <dockerDirectory>${project.basedir}/docker</dockerDirectory> <!--指定远程dockerapi地址--> <dockerHost>http://192.168.129.162:2375</dockerHost> <!--copy资源--> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <!--dockerbuilddockerfile时:设置镜像创建时的变量--> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin>

3.3.码头工人:建造

使用命令$mvncleanpackagedocker:build-dmaven.test.skip=true构建映像,并检查映像是否在docker服务器上成功上传:

3.4码头工人:标签

docker命令行格式为:#dockertag

插件配置
<配置>补充配置:

<configuration> <image>jhs/${project.artifactId}:${project.version}</image> <!--dockertag打标签--> <newName>192.168.129.160:5000/${project.artifactId}:${project.version}</newName> </configuration>

标记镜像以准备后续推送:mvncleandocker:tag-dmaven.test.skip=true-dskipcodkerbuild

3.5码头工人:推

插件配置
<配置>补充配置:

<configuration> <!--dockerpush推送到远程镜像仓库--> <!--serverId:为在mavensetting.xml配置的server信息id--> <serverId>nexus-docker-registry</serverId> <registryUrl>192.168.129.160:5000</registryUrl> <!--打上tag的新镜像push到nexus--> <imageName>192.168.129.160:5000/${project.artifactId}</imageName> </configuration>

将上述标记的图像推送到私有服务器Nexus:MVNCleanDocker:push-dmaven.test.skip=true-dskipdockerbuild-dskipdockertag

3.6docker插件参数

  • -DskipDockerBuild跳过映像构建
  • -DskipDockerTag跳过图像标记
  • -DskipDockerPush跳过图像推送
  • -DskipDockerto跳过任何Docker目标
  • 3.7将命令绑定到maven阶段

    <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-image</id> <phase>package</phase> <goals> <goal>tag</goal> </goals> <configuration> <image>jhs/${project.artifactId}:${project.version}</image> <newName>192.168.129.160:5000/${project.artifactId}:${project.version}</newName> </configuration> </execution> <execution> <id>push-image</id> <phase>deploy</phase> <goals> <goal>push</goal> </goals> <configuration> <!--dockerpush推送到远程镜像仓库--> <!--serverId:为在mavensetting.xml配置的server信息id--> <serverId>nexus-docker-registry</serverId> <registryUrl>192.168.129.160:5000</registryUrl> <imageName>192.168.129.160:5000/${project.artifactId}</imageName> </configuration> </execution> </executions>

    3.8最佳实践

    <properties> <docker.host>http://192.168.129.162:2375</docker.host> <docker.registry.url>192.168.129.160:5000</docker.registry.url> </properties> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <imageName>dic/${project.artifactId}:${project.version}</imageName> <!--添加额外的指定标签(可配置多个),若果没做指定,则为latest--> <!-- <imageTags> <imageTag>${project.version}</imageTag> </imageTags> --> <!--指定Dockerfile路径:项目根路径下--> <dockerDirectory>${project.basedir}/docker</dockerDirectory> <!--指定远程dockerapi地址--> <dockerHost>${docker.host}</dockerHost> <!--copy资源--> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <!--dockerbuilddockerfile时:设置镜像创建时的变量--> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-image</id> <phase>package</phase> <goals> <goal>tag</goal> </goals> <configuration> <image>dic/${project.artifactId}:${project.version}</image> <newName>${docker.registry.url}/${project.artifactId}:${project.version}</newName> </configuration> </execution> <execution> <id>push-image</id> <phase>deploy</phase> <goals> <goal>push</goal> </goals> <configuration> <!--dockerpush推送到远程镜像仓库--> <!--serverId:为在mavensetting.xml配置的server信息id--> <serverId>nexus-docker-registry</serverId> <registryUrl>${docker.registry.url}</registryUrl> <imageName>${docker.registry.url}/${project.artifactId}</imageName> </configuration> </execution> </executions> </plugin> </plugins> </build>

    4。Docker私服仓库安装Harbor步骤详解(补充)

    https://www.jb51.net/article/161964.htm

    这就是这篇关于一键部署idea-connecteddocker的文章。有关idea-connecteddocker一键部署的更多信息,请搜索我们以前的文章或继续浏览下面的相关文章。希望大家以后能多多支持我们!

    欢迎分享,转载请注明来源:内存溢出

    原文地址: http://outofmemory.cn/zz/774228.html

    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    上一篇 2022-05-03
    下一篇 2022-05-03

    发表评论

    登录后才能评论

    评论列表(0条)

    保存