'docker volume custom mount point [duplicate]

I'm new to Docker and I was playing around with docker volume. I wanted to specify the location where docker volume stores the data. Much like when we provide the -v option when we execute docker run. Ex : -v /somefolder/:/var/somefolder

How can we set a custom Mountpoint when we create a docker volume. I didn't find any options on docs.

When I inspect the volume

[                                                                                        
    {                                                                                    
        "Name": "sampleproject_mysql_data",                                              
        "Driver": "local",                                                               
        "Mountpoint": "/mnt/sda1/var/lib/docker/volumes/sampleproject_mysql_data/_data", 
        "Labels": null,                                                                  
        "Scope": "local"                                                                 
    }                                                                                    
]   

I get something like above.

Is there a way we can set custom Mountpoint. Through docker volume command or through docker-compose.yml?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source