10

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.

AATHITH RAJENDRAN
  • 4,689
  • 8
  • 34
  • 58
Rox
  • 2,647
  • 15
  • 50
  • 85

3 Answers3

25

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

Rao
  • 20,781
  • 11
  • 57
  • 77
  • 9
    Amazing that I have to search StackOverflow for `The built-in local driver on Linux accepts options similar to the linux mount command` because that piece of information is not listed on any relevant page of the official Docker documentation (https://docs.docker.com/compose/compose-file/#volume-configuration-reference, https://docs.docker.com/storage/volumes/ or https://docs.docker.com/storage/storagedriver/select-storage-driver/). – Dan Nissenbaum Feb 17 '18 at 22:10
  • For those interested or who would find it helpful, some links to the linux `mount` command documentation: http://man7.org/linux/man-pages/man8/mount.8.html and http://www.tutorialspoint.com/unix_commands/mount.htm – Dan Nissenbaum Feb 17 '18 at 22:17
  • Also in case it's useful - here's a link to another StackOverflow posting that mentions a different local storage volume type that actually allows you to select the location for it on the host: https://stackoverflow.com/a/36321403/368896 – Dan Nissenbaum Feb 17 '18 at 22:52
  • For readers: a now-deleted answer claimed the above answer would/does not work, and referred to [this related answer](https://stackoverflow.com/questions/52089499/create-docker-volume-with-limited-size/52097560#52097560). – halfer Sep 16 '18 at 09:06
15

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
Victor Mota
  • 1,219
  • 12
  • 17
2

Leaning on the answer of Rao, there are now some udpated docs and example on their docs.docker page:

This example volume creation is taken from this page:

$ docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
foo
theDrifter
  • 1,631
  • 6
  • 24
  • 40