【问题标题】:docker ADD with symlinks带有符号链接的 docker ADD
【发布时间】:2021-11-07 20:29:19
【问题描述】:

当我 sudo docker build -t test -f 7.1/Dockerfile . docker 在步骤 8/10 失败时:

Step 8/10 : ADD etc/php /usr/local/etc/php
ADD failed: file not found in build context or excluded by .dockerignore: stat etc/php: file does not exist

我不明白。 etc/php 符号链接到另一个目录。这不应该有效吗?

如果我这样做 ls -latr etc/php 我会得到这个:

lrwxrwxrwx 1 scbn scbn 43 Sep 11 17:48 etc/php -> /home/neubert/devops/containers/common/etc/php

如果我这样做 cd etc/php && ls -latr 我会得到这个:

total 84
drwxr-xr-x 2 scbn scbn  4096 Jan  3  2021 conf.d
drwxr-xr-x 5 scbn scbn  4096 Jan  3  2021 ..
-rw-r--r-- 1 scbn scbn 70125 Jan 26  2021 php.ini
drwxr-xr-x 3 scbn scbn  4096 Jan 26  2021 .

【问题讨论】:

  • Shouldn't that work? 不行,因为 docker 只能访问构建上下文,不能从外部访问。

标签: docker ubuntu symlink ubuntu-20.04 wsl-2


【解决方案1】:

$ docker build --help

用法:docker build [OPTIONS] PATH |网址 | -

这里PATH | URL | -就是所谓的构建上下文,你通常使用.,但也可以是其他路径。当 docker build 时,它会将build context 中的所有内容 tar,然后将其传递给 docker 引擎。所以,Dockerfile 中的COPY 可以只引用build context 中的项目。

对于您的场景:

lrwxrwxrwx 1 scbn scbn 43 Sep 11 17:48 etc/php -> /home/neubert/devops/containers/common/etc/php

上面我猜符号链接etc/php在你的构建上下文中,而真正的文件夹/home/neubert/devops/containers/common/etc/php不在,所以构建失败,你必须以某种方式确保build context中的真实目标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2022-01-04
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    相关资源
    最近更新 更多