Volumes are one of those things that Just Don't Work, even in normal Docker. Our product's dev containers run fine in Docker on macOS on M1 but the filesystem permissions get messed up when running the same ones on Linux. It's just a silly root:root permissions issue, but it's irritating the problem was hidden when running on a Mac.
I've run into this too. My solution was to add some code in entrypoint.sh that looks for the UID/GID of mounted files, then creates a group and user to match. We can then exec the real command as that user.
There is some support for id mapping in the 5.12 kernel that we may be able to take advantage of for this case.
Will have to take a look at how to deal with this for things like volumes.