2022 nga tuig 9 bulan

Dockerfile (path: src/main/docker)

# 根据平台选择
FROM eclipse-temurin:17-jre-focal as builder
#FROM arm64v8/eclipse-temurin:17-jre-focal as builder
#FROM amd64/eclipse-temurin:17-jre-focal as builder

WORKDIR application

ARG JAR_FILE=target/*.jar

COPY ${JAR_FILE} application.jar

RUN java -Djarmode=layertools -jar application.jar extract

# 根据平台选择
FROM eclipse-temurin:17-jre-focal
#FROM arm64v8/eclipse-temurin:17-jre-focal
#FROM amd64/eclipse-temurin:17-jre-focal

WORKDIR application

COPY --from=builder application/dependencies/ ./

COPY --from=builder application/spring-boot-loader/ ./

COPY --from=builder application/snapshot-dependencies/ ./

COPY --from=builder application/application/ ./

ENV TZ="Asia/Shanghai"

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENV JVM_OPTS=""

ENV JAVA_OPTS=""

ENTRYPOINT ["sh","-c","java $JVM_OPTS $JAVA_OPTS org.springframework.boot.loader.JarLauncher"]

使用

mvn clean package
mvn spring-boot:build-image

前置准备

yum update -y
yum upgrade -y

下载MySQL 5.7安装源

wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm

安装MySQL源

rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

导入密钥

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

启动MySQL

# 启动
systemctl start mysqld.service
# 查看状态
systemctl status mysqld.service

打印如下日志

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2022-08-22 17:54:55 CST; 26s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 23800 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 23750 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 23804 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─23804 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

8月 22 17:54:52 dev systemd[1]: Starting MySQL Server...
8月 22 17:54:55 dev systemd[1]: Started MySQL Server

获取初始化密码

grep 'temporary password' /var/log/mysqld.log

打印:

2022-08-22T09:54:53.189408Z 1 [Note] A temporary password is generated for root@localhost: frkKsK_:9Pqk

这里的`frkKsK_:9Pqk`就是密码

参考

https://cloud.tencent.com/developer/article/1886339