Example below creates dbdata named volume and references it inside db service:
version: \'2\'
services:
db:
image: mysql
volumes:
The location of named volumes is managed by docker; if you want to specify the location yourself, you can either "bind mount" a host directory, or use a volume plugin that allows you to specify a path.
You can find some details in another answer I posted recently; https://stackoverflow.com/a/36321403/1811501