Create docker volume with limited size

百般思念 提交于 2019-11-29 02:32:06

This is actually possible using dockers local volume driver. This driver accepts options similar to the linux mount options. Check out this excellent answer.

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.

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 volumes have "drivers" attached to them. The default driver is one called "local" and all it does is creates a directory in /var/lib/docker and mounts it to the container. There's no option to specify (or limit) the volume's size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!