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
Newsletter
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

  • The Window Closes: Why I Switched to Kotlin Before the Codebase Got Too Big
  • After the AI Commit: What Eight Retrospectives Taught Me About Working With Coding Agents
  • Multi-Agent Orchestration on AWS With AgentCore Runtime and A2A
  • Vision-Language Models in 2026: From Research Breakthroughs to Cloud-Native Production Systems

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Dec. 27, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
25.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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