【问题标题】:How do you copy any folder to a Docker container - while the Dockerfile is present in that folder?当 Dockerfile 存在于该文件夹中时,如何将任何文件夹复制到 Docker 容器?
【发布时间】:2017-10-30 19:53:28
【问题描述】:

假设我在 git 上有一个 repo - REPO,我已将其链接到 Docker Cloud 以进行自动构建。构建需要我将整个 REPO 文件夹复制到容器中。

有什么方法可以让 Dockerfile inside REPO 可以将其内容复制到容器中?我查过ADDCOPY,但它们只有在Dockerfile 存在于REPO 之外的一个目录中时才有效。

FOLDER |-> Dockerfile REPO -- 有效

FOLDER |-> REPO |-> Dockerfile -- 不起作用

甚至是通配符,比如命令: ADD ./* /root/ 似乎不起作用。

【问题讨论】:

    标签: linux docker containers linux-containers


    【解决方案1】:

    完全有可能做到这一点。成为. 的根FOLDER(如您所见)。你需要:

    docker build . -f REPO/Dockerfile -t imagename
    

    相对于. 执行COPYADD

    【讨论】:

      【解决方案2】:

      如果我理解正确,以下 dockerfile 可以满足您的需求:

      FROM alpine
      
      RUN mkdir /test
      WORKDIR /test
      
      COPY ./ /test/
      
      CMD ["/bin/sh"]
      

      $dir 中输入以下内容,并从$dir 运行docker build:

      Dockerfile somefile   somefolder
      

      docker镜像中的/test/包含:

      /test # ls
      Dockerfile  somefile    somefolder
      

      【讨论】:

      • COPY ./* /test/ 命令忽略文件夹结构。它只是将所有文件和文件夹内容转储到test
      • 我注意到,copy ./ 没有 * 但至少在我的测试系统上保留了它(docker 版本 17.03.1-ce)
      猜你喜欢
      • 2016-10-13
      • 1970-01-01
      • 2020-11-17
      • 2016-02-28
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      相关资源
      最近更新 更多