Detailed explanation of Docker data backup and recovery process

Detailed explanation of Docker data backup and recovery process

The data backup operation is very easy. Execute the following command:

docker run --volumes-from mydata --name backupcontainer -v $(pwd):/backup/ ubuntu
tar cvf /backup/backup.tar /usr/share/nginx/html/

Command Explanation:

First, use --volumes-from to connect to the container to be backed up.

The -v parameter is used to mount the current directory to the /backup directory of the container.

Next, back up the contents of the /usr/share/nginx/html directory in the container to the backup.tar file in the /backup directory. Since the current directory has been mapped to the /backup directory of the container, the compressed files backed up in the /backup directory of the container can be immediately seen in the current directory.

The execution results are as follows:

recover

Create a container

First, create a container. This container is the container that will use the recovered data. I will create an nginx container as follows:

docker run -itd -p 80:80 -v /usr/share/nginx/html/ --name nginx3 nginx

Create a container named nginx3 and mount a data volume.

recover

Data recovery requires a temporary container, as follows:

docker run --volumes-from nginx3 -v $(pwd):/backup nginx tar xvf/backup/backup.tar

Command Explanation:

First, use the --volumes-from parameter to connect to the backup container, which is nginx3 created in the first step.

Then map the current directory to the /backup directory of the container.

Then perform the decompression operation to decompress the backup.tar file. The decompressed file location description is an address within the container, but this address has been mapped to the current directory in the host machine, so the file to be decompressed here is actually the file in the current directory of the host machine.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Steps to restore code from a Docker container image
  • Detailed explanation of psql database backup and recovery in docker
  • Detailed explanation of backup, recovery and migration of containers in Docker
  • Detailed explanation of Docker private warehouse recovery example
  • How to restore docker container data

<<:  Vue implements the method of displaying percentage of echart pie chart legend

>>:  Implementation of MySQL select in subquery optimization

Recommend

How to set up ssh password-free login to Linux server

Every time you log in to the test server, you alw...

Examples of importing and exporting MySQL table data

This article describes the import and export oper...

Tutorial on installing and configuring remote login to MySQL under Ubuntu

This article shares the MySQL installation and co...

Detailed explanation of the role of brackets in AngularJS

1. The role of brackets 1.1 Square brackets [ ] W...

Vue+Openlayer realizes the dragging and rotation deformation effect of graphics

Table of contents Preface Related Materials Achie...

How to enable the slow query log function in MySQL

The MySQL slow query log is very useful for track...

VMware virtual machine three connection methods example analysis

NAT In this way, the virtual machine's networ...

Vite introduces the implementation of virtual files

Table of contents background Importing virtual fi...

MySQL master-slave principle and configuration details

MySQL master-slave configuration and principle, f...

Public free STUN servers

Public free STUN servers When the SIP terminal us...

JS calculates the probability of winning based on the prize weight

Table of contents 1. Example scenario 1.1. Set th...