如果您需要一个指向主机文件系统位置的命名卷(由于可以进行主机安装,因此需要重新设计轮子,但是似乎有很多人在要求它),所以有本地持久文件系统驱动程序。这包含在Docker的插件列表中。
更新:也可以使用默认本地卷驱动程序将命名卷绑定安装到主机上的任何目录。这使您可以利用命名卷的自动初始化功能,这是主机卷中所没有的,但是有一个缺点,即如果丢失了docker,它不会创建主机目录(相反,卷安装会失败)。您可以通过以下几种方法创建此命名卷:
# create the volume in advance $ docker volume create --driver local --opt type=none --opt device=/home/user/test --opt o=bind test_vol # create on the fly with --mount $ docker run -it --rm --mount type=volume,dst=/container/path,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=/home/user/test foo # inside a docker-compose file ... volumes: bind-test: driver: local driver_opts: type: none o: bind device: /home/user/test ...



