Backing up a Docker Container

Last Updated : 29 Sep, 2026

Backing up Docker containers helps protect application files and makes it easier to restore, version, and share projects. Docker allows you to save a container's filesystem as a TAR file and push the backup image to Docker Hub.

  • Save the container filesystem as a .tar file locally.
  • Use the backup to recover the container when needed.
  • Maintain different versions of your Docker application.
  • Push the backup image to Docker Hub for easy access and collaboration.

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
Creating a Container and File
Creating a Container and File

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 
Copying Container ID
Copying 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
Committing the Container
Committing the Container

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
Saving Backup
Saving Backup

You will find the backup Tar file in your Home Directory.

Tar File
Tar File

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
Pushing Image
Pushing Image
Comment