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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

  • Why Stable RAG Answers Can Still Hide Unstable Evidence
  • Implementing Secure API Gateways for Microservices Architecture
  • Liquid Glass, Material 3, and a Lot of Plumbing
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering
  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.5K 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

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook