虚拟机Docker Idea Java项目测试并部署

本文介绍了如何在虚拟主机上配置Docker服务,启用远程访问,并使用IntelliJ IDEA的Docker插件进行Java项目的测试和一键部署。通过修改Docker服务配置文件,打开2375端口,实现远程连接。接着展示了一个简单的Java Demo程序,并提供了Dockerfile示例,用于构建和运行Java应用。

Docker Idea Java项目测试并部署

1. 虚拟主机配置Docker服务

​ 如果使用idea编辑器的话,可以使用docker插件来远程使用服务器(虚拟机)上的docker,简单方便快捷的使用docker,更重要的是使用插件可以实现项目的一键部署,当然这还需要一些简单的配置。 默认的dokcer是不支持远程访问的,需要加点配置,开启Docker的远程访问

image-20220514213443027

sudo vim /lib/systemd/system/docker.service

修改如下:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket 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

# 注释此行,复制一行 最后添加 -H tcp://0.0.0.0:2375 如果有防火墙 必须allow 2375端口
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375

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=infinit
# 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

sudo systemctl daemon-reload

sudo systemctl restart docker

sudo systemctl status docker

image-20220514214916961

2. idea新建java项目

image-20220514215817072

image-20220514215903095

image-20220514215950082

image-20220514220039396

image-20220514220743554

image-20220514221356530

image-20220514221541597

image-20220514221514136

#创建Demo.java
public class Demo {
    public static void main(String[] args) {
        System.out.println("hello woeld");
    }
}

image-20220514221757270

image-20220514221947997

image-20220514222212685

From ubuntu
Maintainer webrx <webrx@126.com>
Add jdk-18.tar.gz /usr/local/
Run mv /usr/local/jdk-18.0.1 /usr/local/jdk
Copy src/Demo.java /tmp
Env JAVA_HOME /usr/local/jdk
Env CLASSPATH .:$JAVA_HOME/lib
Env PATH .:$PATH:$JAVA_HOME/bin
Workdir /tmp
Volume /tmp
Run java Demo.java

image-20220514222553911

image-20220514224204003

image-20220514224233436

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值