https://www.centos.bz/2018/02/%E5%AE%9A%E5%88%B6entrypoint%E8%87%AA%E5%8A%A8%E4%BF%AE%E6%94%B9docker%E4%B8%ADvolume%E7%9A%84%E6%9D%83%E9%99%90/

……….

Other way

1、make shell and run shell, before run docker-compose.

  
mkdir ./data  
sudo chown docker ./data  
#sudo chown user01 ./data  
sudo chmod g+rwx ./data  
sudo chgrp 994 ./data  

Directory exist and correct Access. 994 or 50 or 1000 see /etc/passwd or /etc/group

2、But sometime OS install docker by you don’t know way… 
maybe have user dockerroot、group dockerroot or only group docker

you maybe already run   sudo usermod -a -G docker $(whoami)  100% in docker group.

A. This time chmod 777 ./data , let docker-compose run

B. ls -al ./data   see who make directory or file

C. get this user  “user01”, chown user01 ./data

D. run docker-compose now have correct aceess Permission

E. chmod 774 ./data