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

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

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

xml 复制代码
<plugin>
	<groupId>com.spotify</groupId>
	<artifactId>docker-maven-plugin</artifactId>
	<version>1.2.2</version>
</plugin>

或者

xml 复制代码
<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

bash 复制代码
vi /usr/lib/systemd/system/docker.service

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

完整信息如下

bash 复制代码
[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项目

bash 复制代码
mvnd clean package -DskipTests=true

4 编写dockerfile

点击文件左侧的运行

点击 run 以后,则会开始执行打包操作

切换到服务器也可以查看到

如果需要推送到远程仓库,右键镜像,push

然后选择相应的仓库即可

相关推荐
木头左35 分钟前
Docker容器化技术中的联合文件系统原理探究
docker·容器·eureka
itachi-uchiha1 小时前
Docker部署Hive大数据组件
大数据·hive·docker
Lw老王要学习2 小时前
Linux容器篇、第二章_01Ubuntu22 环境下 KubeSphere 容器平台高可用搭建全流程
linux·运维·服务器·k8s·kubesphere·容器化
deletion丶2 小时前
在 Windows 系统上运行 Docker 容器中的 Ubuntu 镜像并显示 GUI
docker
杰哥技术分享4 小时前
IDEA 打开文件乱码
java·ide·intellij-idea
猫头虎4 小时前
[特殊字符]解决 “IDEA 登录失败。不支持早于 14.0 的 GitLab 版本” 问题的几种方法
java·ide·网络协议·http·https·gitlab·intellij-idea
罗技1235 小时前
我用Amazon Q写了一个Docker客户端,并上架了懒猫微服商店
运维·docker·容器
爱宇阳6 小时前
使用 Docker Compose 部署 Jenkins(LTS 版)持续集成环境
ci/cd·docker·jenkins
背太阳的牧羊人9 小时前
backend 服务尝试连接 qdrant 容器,但失败了,返回 502 Bad Gateway 问题排查
docker·gateway·qdrant
xiaomu_34710 小时前
基于Linux系统docker封装exe
linux·运维·服务器·docker