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

然后选择相应的仓库即可

相关推荐
sj11637394032 分钟前
docker-compose方式启动Kafka Sasl加密认证(无zk)
docker·kafka
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
令狐少侠20111 小时前
Idea 和 Pycharm 快捷键
pycharm·intellij-idea·idea
西西小飞龙1 小时前
Docker和K8S中pod、services、container的介绍和关系
docker·容器·kubernetes
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
kngines1 小时前
【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.3.1单节点安装(Docker与手动部署)
大数据·elasticsearch·docker
m0_7482554111 小时前
适用于IntelliJ IDEA 2024.1.2部署Tomcat的完整方法,以及笔者踩的坑,避免高血压,保姆级教程
java·tomcat·intellij-idea
新时代丘鸣山12 小时前
Idea java项目结构介绍
java·ide·intellij-idea
飞火流星0202713 小时前
docker安装etcd:docker离线安装etcd、docker在线安装etcd、etcd镜像下载、etcd配置详解、etcd常用命令、安装常见问题总结
docker·容器·etcd