问题描述
关于使用选项 。
我只是想创建一个有限大小的卷,我尝试过
I just want to create a volume with limited size, I tried,
docker volume create --opt o=size=10m hello-volume
,当使用 docker run -v hello-volume:/ hello -it ubuntu / bin / bash运行一个简单的hello world容器时,出现错误就像码头工人:来自守护程序的错误响应:…没有这样的设备…
, when run a simple hello world container with "docker run -v hello-volume:/hello -it ubuntu /bin/bash", I got the error as something like "docker: Error response from daemon: …no such device"…
所以我假设创建卷时必须给出完整的选项,例如
So I assumed we must give the full options when creating the volume, such as
"docker volume create --driver local --opt type=*** --opt device=*** --opt o=size=10m hello-volume"
?
如果是,这里的类型和设备是什么?我猜该设备实际上是任何目录的路径?我尝试过
?If so, what are the "type" and "device" here? I guess the device actually is a path to any directory? I tried
"docker volume create --driver local --opt type=volume --opt device=/ --opt o=size=10m hello-volume".
当尝试以 docker run -v hello-volume:/ hello -it ubuntu方式运行容器时/ bin / bash,我得到以下错误: docker:来自守护程序的错误响应:安装卷'/ var / lib / docker / volumes / hello-volume / _data'时出错:安装带有选项的卷时出错:type ='volume 'device ='/'o ='size = 10m':无此类设备。。
When tried to run the container as "docker run -v hello-volume:/hello -it ubuntu /bin/bash" I got the error as "docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/hello-volume/_data’: error while mounting volume with options: type=‘volume’ device=’/’ o=‘size=10m’: no such device.".
我尝试过
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=10m hello-volume
最终可以运行,但是数据在内存中并不持久。那么,在创建卷时,有谁能指出类型和设备的选项是什么(如果我们不提供任何选项,默认值是什么)?
which finally works, but the data is in memory which is not persistent. So can any one point out what are the options for "type" and "device" when creating the volume (or what’s the default one if we don’t give any options)?
更新:
只是要更新,似乎没有办法限制ext4类型的本地驱动程序中的磁盘大小( (虽然在某些答案和其他帖子中声称是可行的)。主要原因是 ext4文件系统中没有这样的 size参数。
我创建了一个docker卷:
Just want to update that it seems there is no way to limit the disk size in local driver with ext4 type (although claimed doable in several answers and other posts). The major reason is there is no such "size" parameter in "ext4" file system..I created a docker volume:
docker volume create --driver local --opt type=ext4 --opt device=/dev/xvdf --opt o=size=10m hello-volume
然后对其进行检查(泊坞窗体积检查hello-volume),并使用容器进行安装,目前一切正常。
Then inspect it (docker volume inspect hello-volume), and mount it with a container, everything looks fine for now.
[
{
"CreatedAt": "2018-09-01T04:23:57Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/hello-volume/_data",
"Name": "hello-volume",
"Options": {
"device": "/dev/xvdf",
"o": "size=10m",
"type": "ext4"
},
"Scope": "local"
}
]
docker run -v hello-volume:/myfile1 -exec -it ubuntu /bin/bash
但是当您写入/放置大文件时(较大han 10m)在该容器中的 / myfile1中,未引发警报/异常,写入成功。我认为ext4类型的文件系统无法识别 o = size = 10m。
But when you write/put a large file (larger than 10m) in the "/myfile1" in that container, no alert/exception is thrown, the write succeeded. What I think is that "o=size=10m" is not recognized by ext4 type file system.
推荐答案
这实际上是可能的使用dockers local
卷驱动程序。该驱动程序接受类似于linux 选项的选项。看看这个出色的。
This is actually possible using dockers local
volume driver. This driver accepts options similar to the linux mount options. Check out this excellent answer.
您与您的亲密关系尝试。您需要指定-opt设备=
以及-opt type =
选项。这实际上会将主机上的块设备作为卷挂载到Docker容器中。 type
选项指定要使用的文件系统类型。 device
选项要求您指定主机上的块设备之一,例如 / dev / sda2
。您可以通过运行 lsblk
来查看完整列表。
You were close with your attempt. You need to specify a --opt device=
as well as a --opt type=
option. This will essentially mount a block device on your host into your docker container as a volume. The type
option specifies the filesystem type to use. The device
option requires you to specify one of the block devices on your host - /dev/sda2
for example. You can see a complete list by running lsblk
.
但是,映射现有驱动器不是一个好主意。 (除非未使用)。因此,您将需要创建一个新的块设备(使用 lvm
或等效的设备),或者要进行测试,可以尝试使用易失性存储(tmpfs)。
However, it would be a bad idea to map existing drives (unless they are unused). So you will need to create a new block device (using lvm
or equivalent), or for testing you can use volatile storage (tmpfs), as you have tried.
这篇关于创建有限大小的Docker卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!