we have a docker container (mongodb) we are using, with volume mount to store data persistently.
I would like to protect the container and\or volume from accidental deletion by commands 'docker volume prune' or even just 'docker volume rm'
any suggestion?
To prevent accidental deletion of container/volume, there is no any in-built way provided by docker for it.
Check this out.
Also there was a code change to have this feature as mentioned here but it was voted against by solomon hykes because of few reasons.
But there is way to prevent accidental volume deletion while using docker volume prune
.
Check this out.
Hope this helps.
Create a function / alias in the bash profile or bashrc.
function docker {
docker_vol_res="Y"
[[ $1 == vol* ]] && [[ $2 == prune || $2 == rm ]] && echo -n "Do you want to \"$2\" the volume (Y/N)? " && read docker_vol_res
[[ $docker_vol_res == "Y" ]] && /usr/bin/docker $*
}