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.
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
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
Leaning on the answer of Rao, there are now some udpated docs and example on their docs.docker page:
Create a volume and pass the size option with the opt flag
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
Related
i actually play a lot with docker,
and i really don't understand the interest of using the command
docker volume create <volume>
In fact, doing this
docker volume create my_data
docker run --rm -ti -v my_data:/src bash
and only this
docker run --rm -ti -v my_data:/src bash
give exactly the same result, as, in the two scenarii, docker
creates the volume
makes the mapping perfectly
So: what is the interest of the 'create' command ?
As #David Maze already said, you can specify non-default volume options with the docker volume create command, such as labels, a custom driver and options for this driver. The documentation has some interesting examples:
For example, the following creates a tmpfs volume called foo with a size of 100 megabyte and uid of 1000.
docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
foo
Another example that uses btrfs:
docker volume create --driver local \
--opt type=btrfs \
--opt device=/dev/sda2 \
foo
Another example that uses nfs to mount the /path/to/dir in rw mode from 192.168.1.1:
docker volume create --driver local \
--opt type=nfs \
--opt o=addr=192.168.1.1,rw \
--opt device=:/path/to/dir \
foo
I am working on a project where I have to create costum docker containers with costum volumes etc.
As I have to use some driver_opts, I am wondering, what the flags
type: XXX
o: XXX
device: XXX
in a docker-compose file actually mean. I see all the people using them, but the docker manuals and all the resources I found so far couldn't provide satisfying answers. I cannot even find a simple list of what arguments you could pass to all theses flags.
thanks in advance!
From man mount:
mount [-fnrsvw] [-t fstype] [-o options] device mountpoint
To summarize:
type: AAA
o: BBB
device: CCC
is (more or less*) equivalent to: mount -t AAA -o BBB CCC <docker_generated_mountpoint>
* - there is some parsing https://github.com/moby/moby/blob/8d193d81af9cbbe800475d4bb8c529d67a6d8f14/volume/local/local_unix.go#L122
I cannot even find a simple list of what arguments you could pass to all theses flags.
This depends on the particular driver you are using. man mount.cifs differs from man mount.nfs, etc.
From docker-compose driver_opts:
driver_opts specifies a list of options as key-value pairs to pass to the driver for this volume. Those options are driver-dependent.
volumes:
example:
driver_opts:
type: "nfs"
o: "addr=10.40.0.199,nolock,soft,rw"
device: ":/docker/example"
In fact, these opts should exactly same with the one when you use docker run, see Driver-specific options:
$ docker volume create --driver local \
--opt type=nfs \
--opt o=addr=192.168.1.1,rw \
--opt device=:/path/to/dir \
foo
You should in that official document find other opts for other kinds of driver like tmpfs, btrfs etc.
tmpfs:
$ docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
foo
btrfs:
docker volume create --driver local \
--opt type=btrfs \
--opt device=/dev/sda2 \
foo
So, these options is really different depends on the driver type you choose.
I can set volume options when creating a volume:
$ docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
foo
or when I run a container with a --mount flag:
$ docker run \
--mount 'type=volume,src=<VOLUME-NAME>,dst=<CONTAINER-PATH>,volume-driver=local,volume-opt=type=nfs,volume-opt=device=<nfs-server>:<nfs-path>,"volume-opt=o=addr=<nfs-address>,vers=4,soft,timeo=180,bg,tcp,rw"'
<IMAGE>
But how to set options for volumes created in Dockerfile?:
FROM ubuntu
VOLUME /myvol
Looking at the docs, I can only see a flag for setting just a volume driver:
--volume-driver Optional volume driver for the container
In general, if there are "options" for things you might specify in a Dockerfile, you can't set them there. For a VOLUME you can't specify any specific host path , named volume, or device; for an EXPOSEd port you can't specify that it be published on a specific host interface; and so on.
In most cases I'd suggest avoiding a Dockerfile VOLUME declaration, since it mostly has only confusing side effects (notably, preventing any later RUN command from modifying that directory). You will always need to use a docker run -v or similar option to mount a named volume into the container, and that doesn't need a matching VOLUME in the image.
If you do docker run -v to explicitly mount something on a directory declared as a VOLUME, that mount replaces the implicitly created anonymous volume.
I am Trying to mount an EFS inside a docker container running on Premise.
I have tried it with no tls:
docker volume create \
--driver local \
--opt type=nfs \
--opt o=addr=IP-12.29.29.29,rw,nfsvers=4.1,rsize=1048576,tls,wsize=1048576,hard,timeo=600,retrans=2,noresvport \
--opt device=:/ efs-test
docker run --rm -it -v /nfs:/nfs/test -v efs-test:/efs-test --name ubuntu -d ubuntu
it works fine. I can access EFS and write data.
If I use the encryption option while creating the volume, i create a en error:
docker volume create \
--driver local \
--opt type=nfs \
--opt o=addr=IP-12.29.29.29,rw,nfsvers=4.1,rsize=1048576,tls,wsize=1048576,hard,timeo=600,retrans=2,noresvport \
--opt device=:/ efs-test
docker run --rm -it -v /nfs/efs/:/nas/test -v efs-test:/efs-test --name sync -d sync
docker: Error response from daemon: error while mounting volume
'/global/docker/volumes/efs-test/_data': failed to mount local volume: mount :/:/global/docker/volumes/efs-test/_data,
data: addr=10.3.77.107,nfsvers=4.1,rsize=1048576,tls,wsize=1048576,hard,timeo=600,retrans=2,noresvport: invalid argument.
How do I mount an EFS with TLS from on premises using Docker?
I'm working with NFS Volume.
I created a NFS server and on my rasberry pi I set the client and if I mount the directory exposed I can see the content, It's mean that the configuration works.
My goal is to create a volume with the following command:
sudo docker volume create --driver local \
--opt type=nfs \
--opt o=addr=10.0.0.5,rw \
--opt device=:/export/users/reddata \
foo
As I saw in the documentation the create a NFS volume.
My problem is the follow, when I run the container:
sudo docker run -it -p 1880:1880 -v foo:/data --name mynodered -d nodered/node-red
I receive the following error:
docker: Error response from daemon: failed to mount local volume: mount :/export/users/reddata:/var/lib/docker/volumes/foo/_data, data: addr=10.0.0.5: connection refused.
See 'docker run --help'.
I this that something it's not authorized, but I also think that I can mount my shared directory on my pi the configuration previous did should works.
Do you have any idea?
Thanks for your time
Alessandro
I solved the problem.
The problem was the way to create the volume, the right way is:
sudo docker volume create --driver local \
--opt type=nfs \
--opt o=addr=10.0.0.5,nfsvers=4 \
--opt device=:/export/users/reddata \
foo
It's necessary to specify the nfsvers=4.
Another important configuration, in my case it's not necessary to supervise the host that access my folder, in the server my /etc/exports it the follow:
export/users/reddata *(rw,sync,no_subtree_check,insecure)
With the *, I specify all IPs on the network.
Best Regards
Alessandro