Plenty of images run as a normal user but expect a data folder they can write to. Compose lifecycle hooks let you run a command right after start, optionally as root, while the app itself keeps running as that normal user.
services:
app:
image: example/app:1.0
user: "1000:1000"
volumes:
- data:/data
post_start:
- command: chown -R 1000:1000 /data
user: root
volumes:
data:
The hook runs after the container has started. The docs list command as required, plus optional user, privileged and environment. There is a matching pre_stop hook for something that should happen before the container stops, like flushing a cache.
Hooks arrived in Compose 2.30, so on older versions the file is rejected. I would check with docker compose config first.
The hook and the app start at about the same time, so do not count on the command finishing before the app touches /data. For setup that must be done first, a one-shot init service with depends_on and service_completed_successfully is the safer pattern. A chown -R on a huge volume on every start can also take a while.
Further reading: Use lifecycle hooks, Compose file reference: post_start