一、
[root@localhost ~]# systemctl disable firewalld --now
[root@localhost ~]# setenforce 0
二、
先去VMware Workstation Pro挂载镜像
[root@localhost ~]# mount /dev/sr0 /mnt/ [root@localhost ~]# mkdir /opt/centos/ [root@localhost ~]# cp -r /mnt/* /opt/centos/
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost ~]# rm -rf *
[root@localhost ~]# vi yum.repo 摁i 键,然后粘贴下面这段进去 [centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1 摁 shift + : 输入wq 回车保存
[root@localhost ~]# yum repolist [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 wget [root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
三、
[root@localhost ~]# yum install epel-release docker-ce container-selinux -y [root@localhost ~]# systemctl enable docker --now
四、
[root@localhost ~]# vi /etc/docker/daemon.json
粘贴下面这段进去
摁 i
{
"insecure-registries" : ["0.0.0.0/0"],
"registry-mirrors": ["https://5twf62k1.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
shift+:
输入wq,回车保存
[root@localhost ~]# systemctl restart docker [root@localhost ~]# vi /lib/systemd/system/docker.service
粘贴下面这段然后保存
[root@localhost ~]# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
#加载配置
[root@localhost ~]# systemctl daemon-reload
#重启服务
[root@localhost ~]# systemctl restart docker.service
然后打开idea新建项目
package com.example.testhello;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class testhello1 {
@GetMapping("/test")
public String hello(){
return "hello test spring!";
}
}
粘贴下面这段
4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.7 com.example demo2 0.0.1-SNAPSHOT demo2 demo2 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test ${project.artifactId} org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 1.2.1 build-image package build cainiao/${project.artifactId} latest java /ROOT ["java", "-version"] project.build.finalName}.jar是打包后生成的jar包的名字-->["java", "-jar", "/${project.build.finalName}.jar"] http://10.83.234.130:2375 / ${project.build.directory} ${project.build.finalName}.jar
有些idea版本不同,给端口会不一样,我这是2021版本的。
可以看到镜像和容器都构建成功了
访问http://虚拟机ip:8080/hello



