Very inconsistent behaviour sharing the same volume and populating the folder in a Compose multi-stage build. Not all files are visible, only files from one container or another (depends on the run).
- Shared volume is 
public - Container 
caddymountspublicat/srv/public/ - Container 
phpmountspublicat/var/www/html/public/ 
During the build, both write something in their public folder. The resulting volume only show files from the caddy stage or php stage, but not both.
In this run, public/build/ is missing:
$ docker compose exec caddy ls -la public
total 12
drwxr-xr-x    3 root     root          4096 May 18 17:47 .
drwxr-xr-x    1 root     root          4096 May 18 17:40 ..
drwxr-xr-x    3 root     root          4096 May 18 17:47 bundles
Same output for php service:
$ docker compose exec php ls -la public
total 12
drwxr-xr-x    3 root     root          4096 May 18 17:47 .
drwxrwxrwt    1 www-data www-data      4096 May 18 17:47 ..
drwxr-xr-x    3 root     root          4096 May 18 17:47 bundles
The docker file:
# [STAGE] php-prod
FROM php:fpm-alpine AS php
WORKDIR /var/www/html
# Create public/bundles/foo/bar.js
RUN set -eux; \
    mkdir -p public/bundles/foo; \
    touch public/bundles/foo/bar.js
# [STAGE] caddy
FROM caddy:latest as caddy
WORKDIR /srv
# Create public/build/baz.js
RUN set -eux; \
    mkdir -p public/build; \
    touch public/build/baz.js
And the Compose file:
version: "3.9"
services:
  caddy:
    build:
      context: ./
      target: caddy
    volumes:
      - public:/srv/public/
  php:
    build:
      context: ./
      target: php
    volumes:
      - public:/var/www/html/public/
volumes:
  public:
Can you explain the incosistent behaviour?