使用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

然后选择相应的仓库即可

相关推荐
还卿一钵无情泪12 小时前
Docker 部署Unsloth 绕开环境配置难题
运维·人工智能·docker·ai·容器·nlp·干货
打工仔折腾 AI13 小时前
Docker镜像分层与卷挂载到底怎么工作:一次文件系统层面的实测分析
运维·人工智能·后端·python·docker·容器·性能优化
极客先躯14 小时前
高级java每日一道面试题-2026年01月20日-实战篇[Docker]-如何实现镜像的跨区域复制?
java·运维·docker·容器·架构图
紫神18 小时前
DDS 通信技术说明
网络·云原生·容器·k8s·dds·弱网
java_logo18 小时前
Docker 部署 DeepSeek Harness:轻松搭建局域网里的 AI Agent 平台
运维·docker·容器·ai agent·deepseek·轩辕镜像·deepseekharness
我不会起名字32219 小时前
Redis 入门(一):Redis 是什么,为什么后端都离不开它
linux·redis·docker·安装·cli
麦壳饼20 小时前
Docker 快速上手:5 分钟运行 SonnetDB
数据库·docker·sonnetdb
吴声子夜歌20 小时前
Docker入门与实战——操作Docker容器
docker
xrlfreedom20 小时前
MCP 面试高频考点:用 Docker 与 Resources 沉淀可复用 Prompts 工作流,怎么答才落地
docker·resources·mcp
九章-悲回风21 小时前
Linux - Docker及常用镜像部署
linux·运维·docker