-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
149 lines (113 loc) · 4.59 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Ver: 1.8 by Endial Fang ([email protected])
#
# 可变参数 ========================================================================
# 设置当前应用名称及版本
ARG app_name=zookeeper
ARG app_version=3.6.1
# 设置默认仓库地址,默认为 阿里云 仓库
ARG registry_url="registry.cn-shenzhen.aliyuncs.com"
# 设置 apt-get 源:default / tencent / ustc / aliyun / huawei
ARG apt_source=aliyun
# 编译镜像时指定用于加速的本地服务器地址
ARG local_url=""
# 0. 预处理 ======================================================================
FROM ${registry_url}/colovu/dbuilder as builder
# 声明需要使用的全局可变参数
ARG app_name
ARG app_version
ARG registry_url
ARG apt_source
ARG local_url
ENV APP_NAME=${app_name} \
APP_VERSION=${app_version}
# 选择软件包源(Optional),以加速后续软件包安装
RUN select_source ${apt_source};
# 安装依赖的软件包及库(Optional)
#RUN install_pkg xz-utils
# 设置工作目录
WORKDIR /tmp
# 下载并解压软件包 wait-for-port
RUN set -eux; \
appName="wait-for-port-1.0.0-1-linux-amd64-debian-10.tar.gz"; \
[ ! -z ${local_url} ] && localURL=${local_url}/bitnami; \
appUrls="${localURL:-} \
https://downloads.bitnami.com/files/stacksmith \
"; \
download_pkg unpack ${appName} "${appUrls}"; \
mv /tmp/wait-for-port-1.0.0-1-linux-amd64-debian-10/files/common/bin/wait-for-port /usr/local/bin/; \
chmod +x /usr/local/bin/wait-for-port;
# 下载并解压软件包 zookeeper
RUN set -eux; \
appName="apache-${APP_NAME}-${APP_VERSION}-bin.tar.gz"; \
appKeys="0x3D296268A36FACA1B7EAF110792D43153B5B5147 \
0x52A7EA3EECAE05B0A8306471790761798F6E35FC \
0xBBE7232D7991050B54C8EA0ADC08637CA615D22C \
0x3F7A1D16FA4217B1DC75E1C9FFE35B7F15DFA1BA \
0x586EFEF859AF2DB190D84080BDB2011E173C31A2 \
"; \
[ ! -z ${local_url} ] && localURL=${local_url}/zookeeper; \
appUrls="${localURL:-} \
'https://www.apache.org/dyn/closer.cgi?action=download&filename='${APP_NAME}/${APP_NAME}-${APP_VERSION} \
https://www-us.apache.org/dist/${APP_NAME}/${APP_NAME}-${APP_VERSION} \
https://www.apache.org/dist/${APP_NAME}/${APP_NAME}-${APP_VERSION} \
https://archive.apache.org/dist/${APP_NAME}/${APP_NAME}-${APP_VERSION} \
"; \
download_pkg unpack ${appName} "${appUrls}"; \
rm -rf /tmp/apache-${APP_NAME}-${APP_VERSION}-bin/docs;
# 1. 生成镜像 =====================================================================
FROM ${registry_url}/colovu/openjre:8
# 声明需要使用的全局可变参数
ARG app_name
ARG app_version
ARG registry_url
ARG apt_source
ARG local_url
# 镜像所包含应用的基础信息,定义环境变量,供后续脚本使用
ENV APP_NAME=${app_name} \
APP_EXEC=zkServer.sh \
APP_VERSION=${app_version}
ENV APP_HOME_DIR=/usr/local/${APP_NAME} \
APP_DEF_DIR=/etc/${APP_NAME}
ENV PATH="${APP_HOME_DIR}/sbin:${APP_HOME_DIR}/bin:${PATH}" \
LD_LIBRARY_PATH="${APP_HOME_DIR}/lib"
LABEL \
"Version"="v${APP_VERSION}" \
"Description"="Docker image for ${APP_NAME}(v${APP_VERSION})." \
"Dockerfile"="https://github.com/colovu/docker-${APP_NAME}" \
"Vendor"="Endial Fang ([email protected])"
# 从预处理过程中拷贝软件包(Optional),可以使用阶段编号或阶段命名定义来源
COPY --from=builder /usr/local/bin/ /usr/local/bin
COPY --from=builder /tmp/apache-${APP_NAME}-${APP_VERSION}-bin/ /usr/local/${APP_NAME}
# 拷贝应用使用的客制化脚本,并创建对应的用户及数据存储目录
COPY customer /
RUN set -eux; \
prepare_env; \
/bin/bash -c "ln -sf /usr/local/${APP_NAME}/conf /etc/${APP_NAME}";
# 选择软件包源(Optional),以加速后续软件包安装
RUN select_source ${apt_source}
# 安装依赖的软件包及库(Optional)
RUN install_pkg netcat
# 执行预处理脚本,并验证安装的软件包
RUN set -eux; \
override_file="/usr/local/overrides/overrides-${APP_VERSION}.sh"; \
[ -e "${override_file}" ] && /bin/bash "${override_file}"; \
:;
# 默认提供的数据卷
VOLUME ["/srv/conf", "/srv/data", "/srv/datalog", "/srv/cert", "/var/log"]
# 默认non-root用户启动,必须保证端口在1024之上
EXPOSE 2181 2888 3888 8080
# 关闭基础镜像的健康检查
#HEALTHCHECK NONE
# 应用健康状态检查
#HEALTHCHECK --interval=30s --timeout=30s --retries=3 \
# CMD curl -fs http://localhost:8080/ || exit 1
HEALTHCHECK --interval=10s --timeout=10s --retries=3 \
CMD netstat -ltun | grep 2181
# 使用 non-root 用户运行后续的命令
USER 1001
# 设置工作目录
WORKDIR /srv/data
# 容器初始化命令
ENTRYPOINT ["/usr/local/bin/entry.sh"]
# 应用程序的启动命令,必须使用非守护进程方式运行
CMD ["/usr/local/bin/run.sh"]