From 906a1e0d6233cf79548469c2127891d770cb3434 Mon Sep 17 00:00:00 2001 From: away <1819625428@qq.com> Date: Thu, 5 Aug 2021 11:17:13 +0800 Subject: [PATCH] Dockerfile multi-stage build --- deploy.Dockerfile | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/deploy.Dockerfile b/deploy.Dockerfile index 4a76eade6..168010e2b 100644 --- a/deploy.Dockerfile +++ b/deploy.Dockerfile @@ -1,31 +1,40 @@ FROM golang:1.15 as build -RUN rm -rf /var/lib/apt/lists/* -RUN apt-get install apt-transport-https && apt-get update && apt-get install procps\ -&&apt-get install net-tools -#Non-interactive operation -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get install -y vim curl tzdata gawk -#Time zone adjusted to East eighth District -RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata # go mod Installation source, container environment variable addition will override the default variable value ENV GO111MODULE=on ENV GOPROXY=https://goproxy.cn,direct -#map directory to save logs -VOLUME /home/open_im_server/logs -#map directory to save config -VOLUME /home/open_im_server/config - # Set up the working directory -WORKDIR /home/open_im_server +WORKDIR /home/Open-IM-Server # add all files to the container COPY . . -WORKDIR /home/open_im_server/script +WORKDIR /home/Open-IM-Server/script RUN chmod +x *.sh -CMD ["./start_all.sh"] +RUN /bin/sh -c ./build_all_service.sh + +#Blank image Multi-Stage Build +FROM ubuntu + +RUN rm -rf /var/lib/apt/lists/* +RUN apt-get install apt-transport-https && apt-get update && apt-get install procps\ +&&apt-get install net-tools +#Non-interactive operation +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get install -y vim curl tzdata gawk +#Time zone adjusted to East eighth District +RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata + + +#set directory to map logs,config file,script file. +VOLUME ["/home/Open-IM-Server/logs","/home/Open-IM-Server/config","/home/Open-IM-Server/script"] +#Copy scripts files and binary files to the blank image +COPY --from=build /home/Open-IM-Server/script /home/Open-IM-Server/script +COPY --from=build /home/Open-IM-Server/bin /home/Open-IM-Server/bin +WORKDIR /home/Open-IM-Server/script +# "&& tail -f /dev/null " Prevent the container exit after the command is executed +CMD ["./start_all.sh","tail -f /dev/null"] \ No newline at end of file