Referencing Cluster volumes
Description
If I am correct it is currently not possible to use cluster volumes in a docker-compose.yml file like with docker commands:
https://github.com/moby/moby/blob/master/docs/cluster_volumes.md
On the service level the volume directive only supports pipe,npipe,tmpfs and volume . Probably a cluster type should be added or the top level volumedirective needs a type parameter.
According to this doc, such a volume can be created by docker volume create with adequate driver options, and listed by docker volume ls. So you should be able to do the same with a top-level volume (not by service) entry to use the required driver and driver-opts, or refer to an external volume by name if you want to use an existing one.
@cherbst we will close this issue as it seems to have been answered. If you think that is not the case, please re-open this issue. Thank you for your contributions!
As far as I understand the code, there is no translation between compose-/stack-defined cluster volume definitions and actual cluster volumes as of yet.
Service-level volume entries can hold a reference to a cluster volume by using the type cluster, but inlining cluster volume options is left out: https://github.com/docker/cli/blob/7b4cde69673ee7c1d6929749d1a639d748749804/internal/volumespec/types.go#L38-L40
Top-level volume definitions do have a key that is related to cluster volume options (x-cluster-spec, https://github.com/docker/cli/blob/7b4cde69673ee7c1d6929749d1a639d748749804/cli/compose/types/types.go#L478-L486), but specifying that in compose is explicitly ignored by the extensions syntax rule: https://docs.docker.com/reference/compose-file/extension/
So it looks like, cluster volumes can neither be managed nor used through compose files, AS OF YET
Based on what's present it would probably look like this once implemented:
volumes:
my-volume:
driver: my-csi-driver
x-cluster-spec:
group: <group>
access_mode:
scope: <scope>
sharing: <sharing>
mount_volume:
fs_type: <fstype>
capacity_range:
required_bytes: <req_bytes>
limit_bytes: <limit_bytes>
secrets:
- key: <some_key>
secret: <some_docker_secret_id>
#availability: "active" # not sure if needed in spec or only at runtime
driver_opts:
driver_specific_opt_A: <some_value>
driver_specific_opt_B: <some_value>
services:
my-service:
...
volumes:
- type: cluster
source: my-volume
target: "/target/path/in/container"