将ARG传递到父Docker阶段

时间:2019-09-16 21:30:22

标签: docker dockerfile

我们正在编写几小段代码,它们在不同目录下的Dockerfile中几乎使用相同的逻辑。

我想实现类似的目标

ARG image=python:3.7-alpine
FROM $image as python_base
ARG CODE_DIR
ARG API=internal

WORKDIR /orka

# Copy in api files
COPY ./orka_engine_api/orka_api/common.py ./orka_engine/orka_api/
COPY ./orka_engine_api/orka_api/$ARG_API.py ./orka_engine/orka_api/

# Copy in the code
COPY $CODE_DIR ./$CODE_DIR

# make utils and code modules importable
ENV PYTHONPATH $PYTHONPATH:/orka/orka_engine/python_libs/:/orka/$CODE_DIR


FROM python_base as www CODE_DIR=www API=external
RUN apk update && apk add wget && rm -rf /var/cache/apk/*
ENTRYPOINT ["python", "-m", "main"]


FROM python_base as worker CODE_DIR=worker
ENTRYPOINT ["python", "-m", "main"]

即,我希望能够在Dockerfile中专门构建args供父级使用。我可以这样做吗?

0 个答案:

没有答案