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

Vue uses element-ui to implement menu navigation

This article shares the specific code of Vue usin...

About the problems of congruence and inequality, equality and inequality in JS

Table of contents Congruent and Incongruent congr...

Example of how to implement underline effects using Css and JS

This article mainly describes two kinds of underl...

Implementation of TCPWrappers access control in Centos

1. TCP Wrappers Overview TCP Wrappers "wraps...

About Vue's 4 auxiliary functions of Vuex

Table of contents 1. Auxiliary functions 2. Examp...

What you need to know about MySQL auto-increment ID

Introduction: When using MySQL to create a table,...

Summary of considerations for writing web front-end code

1. It is best to add a sentence like this before t...

Detailed explanation of MySQL EXPLAIN output columns

1. Introduction The EXPLAIN statement provides in...

How to hide rar files in pictures

You can save this logo locally as a .rar file and...

CSS3 realizes the childhood paper airplane

Today we are going to make origami airplanes (the...

Docker case analysis: Building a MySQL database service

Table of contents 1 Create configuration and data...

Detailed explanation of TypeScript's basic types

Table of contents Boolean Type Number Types Strin...

Analysis and solution of a.getAttribute(href,2) problem in IE6/7

Brief description <br />In IE6 and 7, in a ...

Best tools for taking screenshots and editing them in Linux

When I switched my primary operating system from ...

Installation and use of mysql on Ubuntu (general version)

Regardless of which version of Ubuntu, installing...