制作sentinel docker镜像

在sentinel官方下载jar包即可运行,但是在部署的时候一个一个的启动jar包很不方便,制作成镜像方便部署和管理。
1)直接运行

# 修改端口号,默认是8080
java -jar sentinel-dashboard-1.7.0.jar --server.port=9090 

2)制作镜像
准备工作

cd /home/docker/sentinel
ls
sentinel-dashboard-1.7.0.jar
jdk-8u144-linux-x64.tar.gz

vim Dockerfile

FROM centos:7
MAINTAINER pader "bartggg@163.com"

RUN set -x \
    && mkdir -p /opt/sentinel \
    && cd /opt/sentinel \
    && mkdir -p logs \
	&& cd logs \
	&& touch start.out \
	&& ln -sf /dev/stdout start.out \
	&& ln -sf /dev/stderr start.out \
    && ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo '$TIME_ZONE' > /etc/timezone \
# 允许挂载该目录
VOLUME /opt/sentinel/logs 

# 添加jdk、sentinel的jar包
ADD jdk-8u144-linux-x64.tar.gz /opt
ADD sentinel-dashboard-1.7.0.jar /opt/sentinel/sentinel-dashboard.jar

# set environment
ENV BASE_DIR="/opt/sentinel" \
    JAVA_HOME="/opt/jdk1.8.0_144" \
    JAVA="/opt/jdk1.8.0_144/bin/java" \
    JVM_XMS="512m" \
    JVM_XMX="512m" \
    JVM_XMN="256m" \
    JVM_MS="32m" \
    JVM_MMS="20m" \
    TIME_ZONE="Asia/Shanghai" \
    SERVER_PORT="8080"

ENV JAVA_OPT="-jar ${BASE_DIR}/sentinel-dashboard.jar -server -Xms=${JVM_XMS} -Xmx=${JVM_XMX} -Xmn=${JVM_XMN} -XX:MetaspaceSize=${JVM_MS} -XX:MaxMetaspaceSize=${JVM_MMS} --server.port=${SERVER_PORT}"

WORKDIR $BASE_DIR
EXPOSE 8080

CMD echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out && nohup $JAVA ${JAVA_OPT} >> ${BASE_DIR}/logs/start.out 2>&1 < /dev/null

构建&运行:

docker build -t bart/sentinel:1.7.0 .
# 查看镜像
docker images
# 运行镜像
docker run -d \
--name sentinel \
--restart always \
-p 8080:8080 \
-v /home/gwc/docker/sentinel:/opt/sentinel/logs \
bart/sentinel:1.7.0

# 测试
curl http://localhost:8080

# 导出镜像
docker save -o /home/gwc/docker/sentinel/sentinel.tar bart/sentinel:1.7.0
# 导入镜像
docker load -i /home/gwc/docker/sentinel/sentinel.tar
posted @ 2020-05-28 17:01  bartggg  阅读(1047)  评论(0编辑  收藏  举报