Docker follow symlink outside context

后端 未结 5 2156
梦如初夏
梦如初夏 2020-12-05 12:54

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_f         


        
相关标签:
5条回答
  • 2020-12-05 12:54

    I know that it breaks portability of docker build, but you can use hard links instead of symbolic:

    ln /some/file ./hardlink
    
    0 讨论(0)
  • 2020-12-05 12:58

    instead of using simlinks it is possible to solve problem administratively by just moving files from sites_available to sites_enabled instead of copying or making simlinks

    so your site config will be in one copy only in site_available folder if it stopped or something or in sites_enabled if it should be used

    0 讨论(0)
  • 2020-12-05 13:01

    If anyone still has this issue I found a very nice solution on superuser.com:

    https://superuser.com/questions/842642/how-to-make-a-symlinked-folder-appear-as-a-normal-folder

    It basically suggests using tar to dereference the symlinks and feed the result into docker build:

    $ tar -czh . | docker build -
    
    0 讨论(0)
  • 2020-12-05 13:05

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

    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.

    0 讨论(0)
  • 2020-12-05 13:11

    One possibility is to run the build in the parent directory, with:

    $ docker build [tags...] -f dir1/Dockerfile .
    

    (Or equivalently, in child directory,)

    $ docker build  [tags...] -f Dockerfile ..
    

    The Dockerfile will have to be configured to do copy/add with appropriate paths. Depending on your setup, you might want a .dockerignore in the parent to leave out things you don't want to be put into the context.

    0 讨论(0)
提交回复
热议问题