Mount host directory with a symbolic link inside in docker container

前端 未结 2 1287
抹茶落季
抹茶落季 2020-12-01 00:39

I mounted the container with this parameter:

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

Inside /home/test in the host there is a symbolic link po

相关标签:
2条回答
  • 2020-12-01 00:53

    One solution is to make Docker mount the original file, but use readlink -f which prints the file's actual location. This way, you can still reference the symlink location in your command, e.g.

    docker run -it -v $(readlink -f /home/test/):/home/test/ ...

    0 讨论(0)
  • 2020-12-01 01:09

    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.

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

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