Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the size of a shared Docker volume?

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.

like image 263
Rox Avatar asked Nov 08 '16 19:11

Rox


People also ask

How do I determine Docker volume size?

You can check size of your docker system. If you want to check from where your containers take storage, you can inspect your volume. In my case, my container takes storage from /var/lib/docker/volumes/myvol1/_data and this file is available in my local system.

How do I specify volumes in Dockerfile?

In Dockerfile you can specify only the destination of a volume inside a container. e.g. /usr/src/app . When you run a container, e.g. docker run --volume=/opt:/usr/src/app my_image , you may but do not have to specify its mounting point ( /opt ) on the host machine.

Do Docker volumes have size limit?

In the current Docker version, there is a default limitation on the Docker container storage of 10Gb. As the BlazeMeter image is ~5 GB when the sample.

Can Docker volumes be shared?

You can manage volumes using Docker CLI commands or the Docker API. Volumes work on both Linux and Windows containers. Volumes can be more safely shared among multiple containers. Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.


2 Answers

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

like image 79
Rao Avatar answered Oct 24 '22 06:10

Rao


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
like image 38
Victor Mota Avatar answered Oct 24 '22 08:10

Victor Mota