为了跟踪 docker-compose 使用的卷,我想使用命名卷。这对于“正常”卷非常有用,例如
version: 2
services:
example-app:
volume:
-named_vol:/dir/in/container/volume
volumes:
named_vol:
但我不知道如何让它在安装本地主机时工作。 我正在寻找类似的东西:
version: 2
services:
example-app:
volume:
-named_homedir:/dir/in/container/volume
volumes:
named_homedir: /c/Users/
或
version: 2
services:
example-app:
volume:
-/c/Users/:/home/dir/in/container/ --name named_homedir
这是否有可能,或者我是否被挂载的匿名卷所困扰?
最佳答案
正如您在此 GitHub 问题中所读到的,挂载命名卷 now is a thing ...自 1.11 或 1.12 起。)。 Driver specific options被记录下来。 GitHub 线程中的一些注释:
docker volume create --opt type=none --opt device=<host path> --opt o=bind
If the host path does not exist, it will not be created.
Options are passed in literally to the mount syscall. We may add special cases for certain "types" because they are awkward to use... like the nfs example [referenced above].
–@cpuguy83
要解决有关如何在撰写中使用它的具体问题,请在 volumes
部分下编写:
my-named-volume:
driver_opts:
type: none
device: /home/full/path #NOTE needs full path (~ doesn't work)
o: bind
这是因为正如 cpuguy83 在链接的 github 线程中所写的那样,选项(在幕后)直接传递给 mount
命令。
编辑:正如评论者...
…@villasv,您可以使用
${PWD}
作为相对路径。…@mikeyjk,您可能需要删除预先存在的卷:
docker volume rm $(docker volume ls -q) OR docker volume prune
…@Camron Hudson,如果出现
没有此类文件或目录
错误,您可能需要阅读 this SO question/ answer因为 Docker 不遵循符号链接(symbolic link),并且您的本地文件系统可能存在权限问题。
关于Docker-compose 命名挂载卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35841241/