当前位置: 首页 > news >正文

使用IDEA官方docker插件构建镜像

此方法同样适用于jetbrains系列的其他开发软件

在IDEA中,如果是maven项目,可以使用插件

<plugin>
	<groupId>com.spotify</groupId>
	<artifactId>docker-maven-plugin</artifactId>
	<version>1.2.2</version>
</plugin>

或者

<plugin>
	<groupId>com.spotify</groupId>
	<artifactId>dockerfile-maven-plugin</artifactId>
	<version>1.4.13</version>
</plugin>

来构建docker镜像,不过还是有些繁琐,可以结合IDEA官方的docker插件,直接快速构建镜像

1 准备

安装docker,Windows可以安装Docker Desktop,CentOS可以参考我之前的文章:CentOS安装docker,安装完成后,需要开启远程访问

1.1 CentOS

vi /usr/lib/systemd/system/docker.service

# 在 ExecStart 后加上参数
 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

完整信息如下

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

1.2 Windows

在这里插入图片描述

2 IDEA配置

在idea中,默认自带了docker插件
在这里插入图片描述
在这里插入图片描述
显示连接成功即可

3 打包项目

这里使用spring boot项目演示,如果是多模块项目,可以结合maven-mvnd这个工具,实现快速打包maven项目

mvnd clean package -DskipTests=true

4 编写dockerfile

点击文件左侧的运行
在这里插入图片描述
在这里插入图片描述
点击 run 以后,则会开始执行打包操作
在这里插入图片描述
切换到服务器也可以查看到
在这里插入图片描述
如果需要推送到远程仓库,右键镜像,push
在这里插入图片描述
然后选择相应的仓库即可

相关文章:

  • 速学python·注释
  • openssl 命令详解
  • MySQL的CRUD操作函数介绍union和union all
  • 2023年终总结
  • Elasticsearch:使用 ELSER v2 文本扩展进行语义搜索
  • RoadMap8:C++中类的封装、继承、多态与构造函数
  • 宣传照(私密)勿转发
  • 使用.Net nanoFramework为ESP32进行蓝牙配网
  • Django 文件上传(十二)
  • prometheus grafana mysql监控配置使用
  • 【JAVA】泛型和Object的区别
  • 深入了解Swagger注解:@ApiModel和@ApiModelProperty实用指南
  • 外包干了3个月,技术退步明显.......
  • 使用 dbgate 在 sealos 上完美管理 mysql pgsql 等数据库
  • 14:00面试,14:08就出来了,问的问题过于变态了。。。
  • Mybatis行为配置之Ⅰ—缓存
  • Linux系统安装MySQL
  • 泛型擦除到底是怎么一回事
  • 福建科立讯通信 指挥调度管理平台 多处文件上传漏洞复现
  • Huffman树实现文件压缩
  • 上博东馆常设陈列入选全国博物馆“十大精品”
  • 新华时评:博物馆正以可亲可近替代“高冷范儿”
  • 美联储官员:美国经济增速可能放缓,现行关税政策仍将导致物价上涨
  • “多规合一”改革7年成效如何?自然资源部总规划师亮成绩单
  • 鄂州交警通报致1死2伤车祸:女子操作不当引发,已被刑拘
  • 河南省委常委会会议:坚持以案为鉴,深刻汲取教训