If you are a Docker Developer, you would surely know how important it is to backup your Docker Container file system. If you are working on an important Docker Application, it becomes very necessary to backup all the files and folders related to it so that in case anything goes wrong, you can get back all those files. It also helps you in managing different versions of your project and also sharing the files and folders of your project among your team members.
In this article, we are going to see how can we back up a Docker Container by saving it as a tar file in your local system. We will also see how you can push that Docker Image Backup directly into your Docker Hub accounts for ease of sharing. Follow the below steps to backup a docker container:
Step 1: Create a Docker Container
For our example, we are going to create an Ubuntu Container with a single file inside it.
sudo docker run -it ubuntu bash
After you fire up the bash, use the below command to create a file.
echo "geeksforgeeks" > geeksforgeeks.txt ls
Step 2: Get the Container ID
You will need the Container ID in order to create the backup.
sudo docker container ls
Note that if the container is not running, you can start the Container using the below command.
sudo docker start <container-id>
Step 3: Commit the Docker Container
To create a snapshot, you need to commit the Container.
sudo docker commit -p 6cb599fe30ea my-backup
Step 4: Saving backup as a Tar file
You can use this command, to save the backup as a Tar File in your local machine.
sudo docker save -o ~/my-backup.tar my-backup
You will find the backup Tar file in your Home Directory.
Step 5: Pushing Image to Docker Hub
In order to push it back to the Docker Hub, you need to have an account on Docker Hub.
Login using your command line and push the Tar File.
sudo docker login sudo docker push my-backup:latest
To conclude, in this article we saw how to create a backup of a Docker Image into a Tar File and pushing it into a Docker Hub account for ease of sharing.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Setup Web Server Over Docker Container in Linux
- Docker compose tool to run multi container applications
- Creating a Network in Docker and Connecting a Container to That Network
- How to Get the IP Address of a Docker Container?
- Docker - Setting up a MongoDB Container
- Mounting a Volume Inside Docker Container
- How to Install Linux Packages Inside a Docker Container?
- Restoring a Docker Container
- Creating an Alpine Docker Container
- Running Commands Inside Docker Container
- How to create a Java Docker Container?
- How to Create a PHP Docker Container?
- Introduction to Amazon Elastic Container Service (ECS)
- How to create your own Docker Customised Image ?
- Introduction to Docker
- How to Build a Web Server Docker File?
- How to Map Ports in Docker?
- Running GUI Applications on Docker in Linux
- Difference between RUN vs CMD vs ENTRYPOINT Docker Commands
- Docker - USER Instruction
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.