本案例以springboot为例
第一种
application.properties
spring.datasource.url=jdbc:mysql://${DB_IP}:${DB_PORT}/${DB_NAME}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=${tz:GMT-6}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PWD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Dockerfile:
FROM openjdk:8-jre-slim
MAINTAINER cdn
PARAMS=""
ENV TZ=GMT-6
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD target/*.jar /app.jar
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
对应的docker 启动脚本:
docker run -e DB_IP=192.168.1.3 -e DB_PORT=2306 -e DB_NAME=aa -e DB_USER=root -e DB_PWD=123456 -p 900:4444 demo:1
第二种
Dockerfile:
FROM openjdk:8-jre-slim
MAINTAINER cdn
PARAMS=""
ENV TZ=GMT-6
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD target/*.jar /app.jar
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://127.0.0.1:2306/aa?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=GMT-6 --spring.datasource.username=root --spring.datasource.password=123456" -p 9999:20600 -v /Users/caidingnu/logs/xxl_job:/data/xxl-job --name xxl-job-admin -d xxl:33
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net