Docker 在上下文之外遵循符号链接 [英] Docker follow symlink outside context

查看:30
本文介绍了Docker 在上下文之外遵循符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

又一个 Docker 符号链接问题.我有一堆文件要复制到我所有的 Docker 构建中.我的目录结构是:

Yet another Docker symlink question. I have a bunch of files that I want to copy over to all my Docker builds. My dir structure is:

parent_dir
    - common_files
        - file.txt
    - dir1
        - Dockerfile  
        - symlink -> ../common_files

在上面的示例中,当我在 dir1 中构建 docker 时,我希望将 file.txt 复制过来.但我不想维护file.txt 的多个副本.根据 此链接,从 docker 版本 0.10 开始,docker build必须

In above example, I want file.txt to be copied over when I docker build inside dir1. But I don't want to maintain multiple copies of file.txt. Per this link, as of docker version 0.10, docker build must

按照容器根目录中的符号链接获取 ADD 构建说明.

Follow symlinks inside container's root for ADD build instructions.

但是当我在 Dockerfile 中使用以下任一行进行构建时,我得到 没有这样的文件或目录:

But I get no such file or directory when I build with either of these lines in my Dockerfile:

添加符号链接/path/dirname添加符号链接/file.txt/path/file.txt

mount 选项不会为我解决这个问题(跨平台...).我试过 tar -czh .|docker build -t 没有成功.

mount option will NOT solve it for me (cross platform...). I tried tar -czh . | docker build -t without success.

有没有办法让 Docker 遵循符号链接并将 common_files/file.txt 复制到构建的容器中?

Is there a way to make Docker follow the symlink and copy the common_files/file.txt into the built container?

推荐答案

这是不可能的,也不会实现.请查看关于github问题#1676的讨论:

That is not possible and will not be implemented. Please have a look at the discussion on github issue #1676:

我们不允许这样做,因为它不可重复.您机器上的符号链接与我的机器不同,相同的 Dockerfile 会产生两种不同的结果.也有指向/etc/paasswd 的符号链接会导致问题,因为它会链接主机文件而不是本地文件.

We do not allow this because it's not repeatable. A symlink on your machine is the not the same as my machine and the same Dockerfile would produce two different results. Also having symlinks to /etc/paasswd would cause issues because it would link the host files and not your local files.

这篇关于Docker 在上下文之外遵循符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆