How I backup named volumes.
- Using a ubuntu image, we mount the named volume (myproj_dbdata) to a /dbdata folder inside the
ubuntu
container. - Create a new folder inside the ubuntu container named /backup.
- Create an archive containing the contents of the /dbdata folder and we store it inside the /backup folder (inside the container).
- Mount the /backup folder from the container to the docker host (your local machine) in a folder named /backups inside the current directory.
docker run --rm -v myproj_dbdata:/dbdata -v $(pwd)/backups:/backup ubuntu tar cvf /backup/db_data_"$(date '+%y-%m-%d')".tar /dbdata