Skip to content

Instantly share code, notes, and snippets.

@kougazhang
Last active September 15, 2021 11:11
Show Gist options
  • Save kougazhang/6a62116d79b279e1f6f679dbb3a574cf to your computer and use it in GitHub Desktop.
Save kougazhang/6a62116d79b279e1f6f679dbb3a574cf to your computer and use it in GitHub Desktop.
分阶段打包 #Dockfile
FROM golang:1.6 as builder
RUN mkdir -p /home/filex
RUN mkdir -p /disk/ssd1
WORKDIR /home/filex
ARG project
COPY ./filex/$project .
FROM builder as job
# 注意,如果 stage 中想要使用 ARG 需要重新在此重新定义
# refer: An ARG instruction goes out of scope at the end of the build stage where it was defined.
# To use an arg in multiple stages, each stage must include the ARG instruction.
# https://stackoverflow.com/questions/53681522/share-variable-in-multi-stage-dockerfile-arg-before-from-not-substituted
CMD ["sh", "-c", "./share/job"]
FROM builder as rawlog
CMD ["sh", "-c", "./share/rawlog"]
FROM builder as upload
CMD ["sh", "-c", "./share/upload"]
# build image command
# --build-arg project=$(job), pass variable $(job) to dockerfile ARG project
# --target upload, assign stage upload
# docker build --build-arg project=$(job) --target upload -t filex-upload .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment