DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Back Up Your Data Volumes to Docker Hub

How to Back Up Your Data Volumes to Docker Hub

Backing up changes that you've made to the container is pretty simple, but backing them up to the data volume is a little more difficult.

Eran Avidan user avatar by
Eran Avidan
·
Dec. 27, 16 · Tutorial
Like (4)
Save
Tweet
Share
22.64K Views

Join the DZone community and get the full member experience.

Join For Free

So, you went and created a data volume for your container. Now, you would like to back up the changes made to the container as well as the data volume itself. The first part is easy; simply commit and push the image to Docker Hub. But what about the data volume? By definition, it is not committed as part of the image.

Why would one like to commit a data volume? The idea is that if we work on a cluster (coreOs for instance), we do not know where our image is going to run at, and we would like it to have its data volume popup next to it as well.

The Docker tutorial suggests that you can backup and restore the data volume locally. We are going to use this technique and add a few more lines to get this backup pushed into Docker Hub for easy future restoration to any location we desire. So, let's get started. These are the steps to follow:

  1. Back up 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

2. 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"

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

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

4. Finally, let's 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 backed-up files and folders. In order use this image (aka restore from backup), we do the following:

1. Run the data container with the data-backup image:

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

 2. Run your image with volumes from the data-container:

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

That's it!

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

Docker (software) Data (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Beginner's Guide to Back-End Development
  • Debugging Threads and Asynchronous Code
  • AIOps Being Powered by Robotic Data Automation
  • Image Classification With DCNNs

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: