One named volume for several apps is tidy, until every app can see the others’ files. A subpath mount limits each container to its own folder.
docker run --rm --mount src=logs,dst=/logs alpine mkdir -p /logs/app1 /logs/app2
docker run -d \
--name=app1 \
--mount src=logs,dst=/var/log/app1,volume-subpath=app1 \
app1:latest
Both commands are from the Docker volumes docs. The first creates two folders in the volume called logs. The second mounts only app1 at /var/log/app1, so that container never sees app2.
Two rules from the docs. You must use --mount, because the docs say you must use it to mount a volume subdirectory. And the subdirectory must exist in the volume before you mount it, otherwise the mount fails.
That second rule is the caveat I would remember. Nothing creates the folder for you, so the first run needs a small step like the mkdir above. The docs page does not name a minimum Docker version, so if the option is rejected on an old install, check the version first.
It is a neat way to give a log collector or a backup job access to one app’s data without mounting the whole volume.
Further reading: Docker volumes: mount a volume subdirectory