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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • MariaDB Vector Edition: Designed for AI
  • How to Integrate a Distributed Database With Event Streaming
  • Introduction to Data Replication With MariaDB Using Docker Containers
  • 5 Simple Tips to Keep Dockerized Apps Secure

Trending

  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  • Automatic Code Transformation With OpenRewrite
  • Integrating Security as Code: A Necessity for DevSecOps
  • A Complete Guide to Modern AI Developer Tools
  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.

By 
Eran Avidan user avatar
Eran Avidan
·
Dec. 27, 16 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
25.1K 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.

Related

  • MariaDB Vector Edition: Designed for AI
  • How to Integrate a Distributed Database With Event Streaming
  • Introduction to Data Replication With MariaDB Using Docker Containers
  • 5 Simple Tips to Keep Dockerized Apps Secure

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!