码头工人卷自定义安装点 [英] docker volume custom mount point

查看:93
本文介绍了码头工人卷自定义安装点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,我在玩 docker volume 。我想指定 docker volume 存储数据的位置。就像当我们执行 docker run 时提供 -v 选项时。 Ex:-v / somefolder /:/ var / somefolder

I'm new to Docker and I was playing around with docker volume. I wanted to specify the location where docker volume stores the data. Much like when we provide the -v option when we execute docker run. Ex : -v /somefolder/:/var/somefolder

我们如何在创建 docker卷时设置自定义的 Mountpoint 。我在文档上没有找到任何选项。

How can we set a custom Mountpoint when we create a docker volume. I didn't find any options on docs.

当我检查卷时

[                                                                                        
    {                                                                                    
        "Name": "sampleproject_mysql_data",                                              
        "Driver": "local",                                                               
        "Mountpoint": "/mnt/sda1/var/lib/docker/volumes/sampleproject_mysql_data/_data", 
        "Labels": null,                                                                  
        "Scope": "local"                                                                 
    }                                                                                    
]   

我得到类似上面的内容。

I get something like above.

推荐答案

如果您需要一个指向主机文件系统位置的命名卷(由于可以进行主机挂载,这有点费时费力,但是看起来很多的人),有一个本地持久文件系统驱动程序。这包含在Docker的插件列表中。

If you need a named volume that's pointing to a host filesystem location (which is a bit of reinventing the wheel since you can do a host mount, but there appear to be a lot of people asking for it), there's the local persist filesystem driver. This is included in Docker's list of plugins.

更新:也可以使用默认的本地卷驱动程序将命名卷绑定安装到主机上的任何目录。这使您能够利用命名卷的自动初始化功能,这是主机卷中所没有的,但有一个缺点是,如果缺少,则docker不会创建主机目录(相反,卷安装会失败)。以下是创建此命名卷的几种方法:

Update: It's also possible to do a bind mount with a named volume to any directory on the host using the default local volume driver. This allows you to take advantage of automatic initialization of named volumes, which is missing from host volumes, but has the one downside that docker doesn't create the host directory if it is missing (instead the volume mount would fail). Here are a few ways you can create this named volume:

  # 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
  ...

这篇关于码头工人卷自定义安装点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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