Docker Community Forums

Share and learn in the Docker community.

How to merge a list of volumes from an extension field into the service definition?

Hi,

I’d like to know whether it is possible to merge a list of volumes with an extension field in a compose file?

I have a few volumes which are common to all services, but then each service has its own additional volume.

The following doesn’t work:

version: "3.7"

x-function: &function
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock

services:
  myservice:
    image: ubuntu
    <<: *function
    volumes:
      - /dev:/dev:ro

myservice won’t get access to the Docker socket. I’ve also tried to add the *function inside the volumes block, but it caused a syntax error.

Thanks in advance

Sadly, Docker is not able to beat the limitation yaml anchors and aliases have: no merge for lists!
see: