Docker-compose 命名的挂载卷 [英] Docker-compose named mounted volume

查看:53
本文介绍了Docker-compose 命名的挂载卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了跟踪 docker-compose 使用的卷,我想使用命名卷.这适用于像

这样的正常"卷

版本:2服务:示例应用程序:体积:-named_vol:/dir/in/container/volume卷:命名卷:

但是我不知道如何在挂载本地主机时使其工作.我正在寻找类似的东西:

版本:2服务:示例应用程序:体积:-named_homedir:/dir/in/container/volume卷:named_homedir:/c/Users/

版本:2服务:示例应用程序:体积:-/c/Users/:/home/dir/in/container/--name named_homedir

这是可能的,还是我一直在使用匿名卷来安装已安装的卷?

解决方案

正如您在此 GitHub 问题中所读到的,挂载命名卷 现在是一件事 ...从 1.11 或 1.12 开始.)驱动程序特定选项 已记录在案.来自 GitHub 线程的一些注释:

docker volume create --opt type=none --opt device=<主机路径>--opt o=绑定

<块引用>

如果主机路径不存在,则不会创建.

<块引用>

选项按字面传递给挂载系统调用.我们可能会为某些类型"添加特殊情况.因为它们使用起来很尴尬……就像 nfs 示例 [上面引用].

–@cpuguy83

要解决有关如何在撰写中使用它的具体问题,请在 volumes 部分下写:

我命名的卷:驱动程序选择:类型:无设备:/home/full/path #NOTE 需要完整路径(~ 不起作用)o:绑定

这是因为 cpuguy83 在链接的 github 线程中写道,选项(在幕后)直接传递给 mount 命令.

正如…评论的那样

  • ...@villasv,你可以使用 ${PWD} 作为相对路径.

  • ...@mikeyjk,您可能需要删除预先存在的卷:

     docker volume rm $(docker volume ls -q)或者docker 卷修剪

  • …@Camron Hudson,如果您有没有这样的文件或目录 出现错误,您可能需要阅读这个问题/答案,因为 Docker 不遵循符号链接,并且您的本地文件系统可能存在权限问题.

In order to keep track of the volumes used by docker-compose, I'd like to use named volumes. This works great for 'normal' volumes like

version: 2
services: 
  example-app:
    volume:
      -named_vol:/dir/in/container/volume
volumes:
  named_vol:

But I can't figure out how to make it work when mounting the local host. I'm looking for something like:

version: 2
services: 
  example-app:
    volume:
      -named_homedir:/dir/in/container/volume
volumes:
  named_homedir: /c/Users/

or

version: 2
services: 
  example-app:
    volume:
      -/c/Users/:/home/dir/in/container/ --name named_homedir

is this in any way possible or am I stuck with anonymous volumes for mounted ones?

解决方案

As you can read in this GitHub issue, mounting named volumes now is a thing … since 1.11 or 1.12.). Driver specific options are documented. Some notes from the GitHub thread:

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

To address your specific question about how to use that in compose, you write under your volumes section:

my-named-volume:
     driver_opts:
           type: none
           device: /home/full/path #NOTE needs full path (~ doesn't work)
           o: bind

This is because as cpuguy83 wrote in the github thread linked, the options are (under the hood) passed directly to the mount command.

EDIT: As commented by…

  • …@villasv, you can use ${PWD} for relative paths.

  • …@mikeyjk, you might need to delete preexisting volumes:

     docker volume rm $(docker volume ls -q)
     OR
     docker volume prune
    

  • …@Camron Hudson, in case you have no such file or directory errors showing up, you might want to read this SO question/ answer as Docker does not follow symlinks and there might be permission issues with your local file system.

这篇关于Docker-compose 命名的挂载卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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