一、介绍
通过多阶段构建可以将使用不同的环境构建可以区分dev、deploy等不同的环境,适用于强迫症患者。通过以下as某某某参数实现多步骤构建(as build中build仅为定义的名字,可以as zhangsan、as lisi等)
官方文档: https://docs.docker.com/develop/develop-images/multistage-build/
个人dockerfile参考文档: https://github.com/xiangys0134/Dockerfile
二、Dockerfile
#
# 描述: java基础编译镜像 jdk java-1.8.0-openjdk java-1.8.0-openjdk-devel apache-maven-3.35.2
#
# github:https://github.com/xiangys0134/Dockerfile/blob/master/dockerfile/XONE/Dockerfile_java_dev
#
# docker hub镜像地址:xiangys0134/xone-java-dev
#
FROM xiangys0134/xone-java-dev:v1.0.3 as build
LABEL maintainer="<yousong.xiang@xuncetech.com>" \
name="rpmbuild" \
author="yousong.xiang" \
version="v1.0.1" \
systemver="Centos7.5" \
desc="xone_java devtoolset" \
build-date="20190109"
# src/java基础代码
COPY src/java /tmp/src/java
# 编译XONE程序
RUN set -ex; \
\
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
source /root/.bashrc; \
cd /tmp/src/java; \
mvn clean compile verify -P production -Dmaven.test.skip=true; \
cd ../..; \
mkdir /data/XONE -p; \
#cp -rf src/java/script/dbservice/*.sql /data/XONE/script; \
mkdir -p /data/XONE/all_libs; \
srvname=`ls src/java/services |grep -v "messaging" |grep -v "proxy-cms"`; \
for srv in {srvname}; \
do \
cp -rf src/java/services/{srv}/target/xone-{srv}-[0-9]*.[0-9]*-SNAPSHOT-distribute/xone-{srv} /data/XONE/; \
mv -f /data/XONE/xone-{srv}/lib/*.jar /data/XONE/all_libs/; \
rm -rf /data/XONE/xone-{srv}/lib/; \
done; \
find /data/XONE/ -name "*.sh" |dos2unix; \
srvname=`ls /data/XONE/ |grep -v "all_libs" |grep -v "sql_files" |grep -v "script"`; \
for srv in {srvname}; \
do \
if [ -e /data/XONE/{srv}/lib ]; then \
rm -rf /data/XONE/{srv}/lib; \
fi; \
ln -sf /data/XONE/all_libs /data/XONE/{srv}/lib; \
done; \
cd /tmp; \
rm -rf /tmp/RPM; \
rm -rf /tmp/conf; \
rm -rf /tmp/src; \
yum clean all
#
# 描述: java基础部署镜像 jdk java-1.8.0-openjdk java-1.8.0-openjdk-devel
#
# github:https://github.com/xiangys0134/Dockerfile/blob/master/dockerfile/XONE/Dockerfile_java_deploy
#
# docker hub镜像地址:xiangys0134/xone-java-depoy
#
FROM xiangys0134/xone-java-depoy:v1.0.3
COPY --from=build /data/XONE /data/XONE
RUN set -ex; \
\
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
yum clean all
USER root
EXPOSE 9761 9762 9763 9766 9767 9768 9769 9781
VOLUME ["/data/XONE"]
WORKDIR /data
CMD ["/usr/sbin/init"]
留言