How to customize the location of global volume in docker-compose?

  docker, question

Problem description

For example

version: '2'
 
 services:
 portainer:
 image: portainer/portainer
 command: -H unix:///var/run/docker.sock
 restart: always
 ports:
 - 9000:9000
 volumes:
 - /var/run/docker.sock:/var/run/docker.sock
 - portainer_data:/data
 
 volumes:
 portainer_data:

This one is calledportainer_dataThe default location for the volume of is managed by docker (/var/lib/Docker/volumes/porter _ data/_ data), then I want to customize a location?

The environmental background of the problem and what methods have you tried?

I changed it to,

volumes:
 portainer_data:/my_data

This is wrong, start to report an error

- ./portainer_data:/data

In order to./The beginning is the directory where docker-compose.yml is located.