Why docker-compose down deletes my volume? how to define volume as external?

Based on the documentation here, the down will remove volumes unless those volume are external

By default, the only things removed are:

* Containers for services defined in the Compose file
* Networks defined in the networks section of the Compose file
* The default network, if one is used

Networks and volumes defined as external are never removed.

However, you want to use the stop and start commands instead. The stop command doesn’t erase volumes or networks and you don’t need to specify them as externals in your docker-compose.yml file.