[backup] How can I backup a Docker-container with its data-volumes?

I know this is old, but I realize that there isnt a well documented solution to pushing a data container (as backup) to docker hub. I just published a short example on how doing so at https://dzone.com/articles/docker-backup-your-data-volumes-to-docker-hub

Following is the bottom line

The docker tutorial suggest you can backup and restore the data volume locally. We are going to use this technique, add a few more lines to get this backup pushed into docker hub for easy future restoration to any location we desire. So, lets get started. These are the steps to follow:

Backup the data volume from the data container named data-container-to-backup

docker run --rm --volumes-from data-container-backup --name tmp-backup -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /folderToBackup

Expand this tar file into a new container so we can commit it as part of its image

docker run -d -v $(pwd):/backup --name data-backup ubuntu /bin/sh -c "cd / && tar xvf /backup/backup.tar"

Commit and push the image with a desired tag ($VERSION)

docker commit data-backup repo/data-backup:$VERSION
docker push repo/data-backup:$VERSION

Finally, lets clean up

docker rm data-backup
docker rmi $(docker images -f "dangling=true" -q)

Now we have an image named data-backup in our repo that is simply a filesystem with the backup files and folders. In order use this image (aka restore from backup), we do the following:

Run the data container with the data-backup image

run -v /folderToBackup --entrypoint "bin/sh" --name data-container repo/data-backup:${VERSION}

Run your whatEver image with volumes from the data-conainter

docker run --volumes-from=data-container repo/whatEver

Thats it.

I was surprised there is no documentation for this work around. I hope someone find this helpful. I know it took me a while to think about this.

Examples related to backup

input file appears to be a text format dump. Please use psql How can I backup a Docker-container with its data-volumes? Backup/Restore a dockerized PostgreSQL database Export MySQL database using PHP only Tar a directory, but don't store full absolute paths in the archive How to extract or unpack an .ab file (Android Backup file) mysqldump with create database line Postgresql 9.2 pg_dump version mismatch How to backup Sql Database Programmatically in C# Opening a SQL Server .bak file (Not restoring!)

Examples related to docker

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker What is the point of WORKDIR on Dockerfile? E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How do I add a user when I'm using Alpine as a base image? docker: Error response from daemon: Get https://registry-1.docker.io/v2/: Service Unavailable. IN DOCKER , MAC How to fix docker: Got permission denied issue pull access denied repository does not exist or may require docker login Docker error: invalid reference format: repository name must be lowercase Docker: "no matching manifest for windows/amd64 in the manifest list entries" OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

Examples related to linux-containers

How can I backup a Docker-container with its data-volumes? How to use sudo inside a docker container? Docker how to change repository name or rename image? How do I assign a port mapping to an existing Docker container?