From 8a69698108e4f462617bc9ccd3ff708d1ba65bdc Mon Sep 17 00:00:00 2001 From: hiparker Date: Sat, 8 May 2021 18:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Docker=20=E9=83=A8?= =?UTF-8?q?=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 36 ++++++++++++++++---------------- db-file/Dockerfile | 14 +++++++++++++ docker-compose.yml | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 db-file/Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index ea1ac2f..4b2966a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,39 +2,39 @@ FROM openjdk:8u222-jre MAINTAINER opsli.com -LABEL version=v1.3.3 +LABEL version=V1.3.3 LABEL description=OPSLI-快速开发平台 LABEL qqGroup=724850675 -# 工作目录 -WORKDIR /usr/local/opsli/opsli-boot +# 设置环境常量 +ENV WORKSPACE=/usr/local/opsli/opsli-boot \ + LOG_PATH=/var/log \ + UPLOAD_PATH=/upload/files \ + TZ=Asia/Shanghai \ + JAR_NAME=opsli-starter-1.3.3.jar -# 暴露端口 -EXPOSE 7000 +# 工作目录 +WORKDIR ${WORKSPACE} # 日志输出 -RUN ["echo","OPSLI 快速开发平台正在 building..."] +RUN ["echo","OPSLI 快速开发平台 building..."] # 创建日志目录 -RUN mkdir -p /var/log +RUN mkdir -p ${LOG_PATH} # 创建文件上传目录 -RUN mkdir -p /upload/files - -# 更改文件名称 -RUN find ./opsli-starter/target -type f -regex ".*\.\(jar\)" | xargs -i mv {} ./opsli-starter/target/opsli-starter.jar +RUN mkdir -p ${UPLOAD_PATH} # 拷贝Jar -ADD ./opsli-starter/target/opsli-starter.jar ./ - -# JVM configs deprecated for removal in opsli -ENV JVM_OPTS=" -Xmx2048m -Xms2048m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 " \ - TZ=Asia/Shanghai \ +ADD ./think-modules/target/${JAR_NAME} ./ # 切换为上海时区 RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \ && echo $TZ > /etc/timezone -ENTRYPOINT java ${JVM_OPTS} -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar opsli-starter.jar - +# 启动镜像 +ENTRYPOINT java -jar ${JAR_NAME} -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom --spring.profiles.active=docker --log.path=${LOG_PATH} --opsli.web.upload-path=${UPLOAD_PATH} +CMD ["-Xmx2048m -Xms2048m -XX:+UseG1GC -XX:MaxGCPauseMillis=200"] +# 暴露端口 +EXPOSE 8080 diff --git a/db-file/Dockerfile b/db-file/Dockerfile new file mode 100644 index 0000000..c0714d8 --- /dev/null +++ b/db-file/Dockerfile @@ -0,0 +1,14 @@ +FROM mysql:8.0.19 + +MAINTAINER opsli.com +LABEL version=V1.3.3 +LABEL description=OPSLI-快速开发平台 +LABEL qqGroup=724850675 + +ENV TZ=Asia/Shanghai + +# 切换为上海时区 +RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \ + && echo $TZ > /etc/timezone + +COPY ./opsli-boot.sql /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f1422c3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3.3' +services: + # 构建 MySQL数据库 这里不指定数据库文件 防止误操作 等隐患问题 + opsli-boot-mysql: + build: ./db-file + image: opsli-boot-mysql + restart: always + environment: + # root 账户默认密码 生产时请更改 + MYSQL_ROOT_PASSWORD: 123456 + MYSQL_ROOT_HOST: '%' + TZ: Asia/Shanghai + LANG: en_US.UTF-8 + container_name: opsli-boot-mysql + command: + --character-set-server=utf8mb4 + --collation-server=utf8mb4_general_ci + --explicit_defaults_for_timestamp=true + --lower_case_table_names=1 + --max_allowed_packet=128M + --default-authentication-plugin=caching_sha2_password + volumes: + - /var/mysql/data:/var/lib/mysql #挂载 MySQL数据 + ports: + - "3306:3306" + + # 构建 Redis + opsli-boot-redis: + image: redis:6.2.3 + restart: always + container_name: opsli-boot-redis + environment: + TZ: Asia/Shanghai + LANG: en_US.UTF-8 + command: redis-server /usr/local/etc/redis/redis.conf --appendonly yes # 表示通过挂载配置文件追加配置 + volumes: + - /var/redis/data:/data #挂载 Redis数据 + - /var/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf #挂载 Redis配置 + ports: + - "6379:6379" + + opsli-boot: + build: ./ + restart: on-failure + depends_on: + - opsli-boot-mysql + - opsli-boot-redis + container_name: opsli-boot + image: opsli-boot + ports: + - "8080:8080" \ No newline at end of file