How to take Docker Container Backup and Push to Docker Hub

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hi, this post is about docker container backup. So, let’s get started.

Docker container backup

Docker containers are much like virtual machines, but they’re lighter and faster. You can run an entire software stack in a single container, and you can replicate that same stack again and again with minimal overhead. It’s an efficient way to package applications for deployment.

But what happens when your container goes down? With Docker, you can just rebuild it—but what happens if you want to keep that data around? That’s where a backup comes in.

There are two main ways to back up your Docker container: the first is via the Docker command-line interface (CLI), and the second is through third-party tools.

The Docker CLI method involves creating a snapshot of your container data before removing it from memory; this will allow you to restore your original container after it crashes or otherwise fails. To do this, run:

docker commit -p <container_id>  <image_name>

The above command will create a new commit for [container id], and attach it as an additional layer onto whatever image was previously used by that container (typically an official image from Docker Hub). This will create an image.

Step1: Here I have created an Nginx container. If you already have an existing container then you can skip this step.

docker run -it nginx
docker container ls
docker container backup
docker container backup
docker container backup

Step2: You must commit the Container in order to create a snapshot.

docker commit -p <container_id>  <image_name>

Step3: Check the docker images with the following command:

docker images

Step4: Ensure to use this command which helps to store the backup to your local system known as a Tar file.

docker save -o ~/my-backup.tar nginx_backup

Push docker image to Docker Hub

Docker Hub is a cloud-based repository that allows users and partners to create, store and circulate container images in the docker. You can access public as well as open-source image repositories using Docker Hub. And you can also use the space to create your own private repositories, automated build functions, webhooks, and workgroups.

For instance, the official PostgreSQL object-relational database management system container image can be downloaded by any person who has the know-how of DevOps from the docker hub to use the application deployed in containers. Apart from this, the person can also choose a customized RDBMS from a private repository.

Docker Hub is a cloud-hosted version of the Docker Registry. As a docker user, you can choose Docker Registry. It is a server-side application that is stateless, accessible, and configurable. And if you prefer to maintain the storage and distribution of Docker images instead of relying on Docker’s service then you can use Docker Registry.

How Docker Hub repositories work


The spaces within Docker Hub where users upload and store container images are what we call image repositories. The repositories that are public help people to use on container images. While private repositories can protect any sensitive or confidential data from unofficial persons.

To push an image to Docker Hub, a user must do the following:

  • Start off by setting the environment variable in the Docker terminal, Docker ID, which is a username that is used by both Docker Cloud and Docker Hub. Then use the docker login command to sign in to Docker Cloud.
docker login
  • Here in this step, ensure to tag the particular image using the docker tag.
docker tag <image_name> <Docker ID>/<new_image_name:tag>
  • Later, just push the image to Docker Hub with the docker push command and check whether the Docker Cloud shows the image in the repository or not.
docker push <Docker ID>/<new_image_name:tag>

Finally, a user is able to pull an image from Docker Hub using the docker pull command.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Jaswinder Singh
Jaswinder Singh
DevOps Engineer

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook