在Docker容器内部使用符号链接挂载主机目录 [英] Mount host directory with a symbolic link inside in docker container

查看:542
本文介绍了在Docker容器内部使用符号链接挂载主机目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下参数安装了容器:

I mounted the container with this parameter:


-v / home / test /:/ home / test

-v /home/test/:/home/test

在主机的/ home / test内部,有一个指向/ mnt /文件夹的符号链接。

Inside /home/test in the host there is a symbolic link pointing to a /mnt/ folder.

但是尽管可以看到指向该链接的链接,但该链接似乎在容器内损坏了:

But that link, although can be seen where is pointing to, seems broken inside the container:

root@f93f72b45013:/var/www/html# cd /home/test/ 
root@f93f72b45013:/home/test# ls -lrt 
total 11956 
lrwxrwxrwx. 1 root root 40 Jul 20 15:55 file -> /mnt/mountedfile/
root@f93f72b45013:/home/test# ls -lrt file/*
ls: cannot access file/*: No such file or directory

是否甚至可以在Docker中完成?我不确定是否有办法。

Is that even possible to be done in docker? I am not sure if is there a way to do it.

我知道我可以直接安装符号链接指向的位置,但是我只是想知道这是否是

I know I can just directly mount where the symbolic link is pointing at but I was just wondering if this is possibe.

推荐答案

符号链接是docker内部的一个巨大挑战。您可以挂载两个目录:

Symlinks are a big challenge inside docker. In your case you can mount both directories:

-v /home/test/:/home/test -v /mnt/mountedfile:/mnt/mountedfile

要使符号链接在容器内外均可工作,它们必须绝对路径,并使用完全相同的名称。

For symbolic links to work both inside and outside the container, they have to be absolute paths and use exactly the same names.

通常,符号链接在docker内部不起作用。我发现这很困难。

In general, symlinks do not work inside docker. I found this the hard way.

这篇关于在Docker容器内部使用符号链接挂载主机目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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