How specify the size of a shared Docker volume?

…衆ロ難τιáo~ 提交于 2019-12-06 02:46:19

问题


If I would like to create a data volume of let´s say 15GB that would be of type ext4, how would I do that?

docker volume create --name vol just creates an empty volume.

docker volume create --opt type=ext4 --name vol creates an ext4 volume but I cannot specify the size of it since ext4 does not support it according to the mount options of ext4.


回答1:


It is possible to specify the size limit while creating the docker volume using size as per the documentation

Here is example command provided in the documentation to specify the same

docker volume create -d flocker -o size=20GB my-named-volume

UPDATE Some more examples from git repository:

The built-in local driver on Linux accepts options similar to the linux mount command:
$ docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000
Another example:
$ docker volume create --driver local --opt type=btrfs --opt device=/dev/sda2




回答2:


Using Docker Compose I was able to do it the following way:

volumes: 
  tmpfs: 
    # For details, see:
    # https://docs.docker.com/engine/reference/commandline/volume_create/#driver-specific-options
    driver: local
    driver_opts:
      o: "size=$TMPFS_SIZE"
      device: tmpfs
      type: tmpfs


来源:https://stackoverflow.com/questions/40494536/how-specify-the-size-of-a-shared-docker-volume

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