How to include files outside of Docker's build context?

前端 未结 14 1081
情话喂你
情话喂你 2020-11-22 07:21

How can I include files from outside of Docker\'s build context using the \"ADD\" command in the Docker file?

From the Docker documentation:

T

14条回答
  •  心在旅途
    2020-11-22 07:39

    I often find myself utilizing the --build-arg option for this purpose. For example after putting the following in the Dockerfile:

    ARG SSH_KEY
    RUN echo "$SSH_KEY" > /root/.ssh/id_rsa
    

    You can just do:

    docker build -t some-app --build-arg SSH_KEY="$(cat ~/file/outside/build/context/id_rsa)" .
    

    But note the following warning from the Docker documentation:

    Warning: It is not recommended to use build-time variables for passing secrets like github keys, user credentials etc. Build-time variable values are visible to any user of the image with the docker history command.

提交回复
热议问题