Docker: volume under bind mount?

Here’s what I’ve got:

version: "3.7"
services:
  php:
    build:
      context: .
      dockerfile: docker/php.docker
    links:
      - mariadb
    env_file: .env
    volumes:
      - type: volume
        source: webpack_assets
        target: /srv/myproject/.webpack
        read_only: true
      - type: volume
        target: /srv/myproject/storage
        consistency: delegated
      - type: tmpfs
        target: /srv/myproject/bootstrap/cache
        consistency: delegated
      - type: bind
        source: .
        target: /srv/myproject
        read_only: true
        consistency: cached
    working_dir: '/srv/myproject'
  webpack:
    image: node:lts
    ports:
      - '8081:8081'
    env_file: .env
    volumes:
      - type: volume
        source: webpack_assets
        target: /srv/myproject/.webpack
      - type: bind
        source: .
        target: /srv/myproject
        read_only: true
        consistency: cached
    working_dir: '/srv/myproject'
    command: sh -c 'yarn && exec node --max_old_space_size=8192 node_modules/.bin/webpack-dev-server'
volumes:
  webpack_assets:

webpack needs read-only access to my project files and it needs to write a special file webpack-assets.json which I’ve moved under a .webpack directory because I don’t think you can mount a single file.

php needs read-only access to this generated file. I would have liked to make it a tmpfs volume but apparently those can’t be shared?? The host system doesn’t need access to this file.

The problem is I get this error when I try to try to mount the volumes this way:

ERROR: for myproject_webpack_1  Cannot start service webpack: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/var/lib/docker/volumes/myproject_webpack_assets/_data\" to rootfs \"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged\" at \"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack\" caused \"mkdir /var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697cRecreating myproject_php_1     ... error

ERROR: for myproject_php_1  Cannot start service php: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/var/lib/docker/volumes/myproject_webpack_assets/_data\" to rootfs \"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged\" at \"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack\" caused \"mkdir /var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack: read-only file system\""": unknown

ERROR: for webpack  Cannot start service webpack: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/var/lib/docker/volumes/myproject_webpack_assets/_data\" to rootfs \"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged\" at \"/var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack\" caused \"mkdir /var/lib/docker/overlay2/bc6896fa1823fbb96963b5afd02ac877b6210ed25712be697c226dc1d1943762/merged/srv/myproject/.webpack: read-only file system\""": unknown

ERROR: for php  Cannot start service php: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/var/lib/docker/volumes/myproject_webpack_assets/_data\" to rootfs \"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged\" at \"/var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack\" caused \"mkdir /var/lib/docker/overlay2/ee4f18947f74ba66fa17775e1b32447e9536609ad527699f3de74ec101d32915/merged/srv/myproject/.webpack: read-only file system\""": unknown

How can I get this to work?

Source: StackOverflow