Learn Docker:7 yourself. Backup and recovery of data volume containers

Source: Internet
Author: User
Tags docker run

Recently, because of the work, various things, busy to die. The user found that the software has a problem, and whether it is not their own operation of the problem, a mouthful of convinced that is a software problem, ask what question when "there is a problem" three word response is also drunk.
It's never been said before. Docker saw the data volume container as if it was useful to know what the data volume container is. The most basic use of data volume containers is to back up, restore, and migrate data volumes.

Backup

Let's create a data container first.

-i-t-v /data--data c9fc7f8eec37


The data data volume container that was created above is attached to the Datastore, based on the previously data-volume container that was persisted by Docker.
In order to verify the backup function of the data volume container, I created a database file in the mounted/data directory and wrote the content "data".

Then, to take advantage of the data volume container backup, use the –volumes-from tag to create a container to load the data container volume and mount the current directory from the host to the container's/backup directory.

-i-t--volumes-fromdata-v $(pwd):/backup c9fc7f8eec37 tar cvf /backup/backup.tar /data

The above code completes this step, and $ (PWD) is the method that Docker supports to specify the current directory, and the understanding of Linux basic commands reveals that Linux is viewing the current directory as the PWD command.
After the container is started, the generated in the current directoryBackup.tarThe file is the backup file for the data container volume.

This allows the data in the data volume container to be backed up.
In short, create a container, mount the data container to be backed up, and mount the data volume (PWd ):/baCkuPMeshRecordto thecapacityDevice/bakCuP,in thecapacityDeviceinPracticeLinepreparedPart/d aTaMeshRecordto the/baCkuP,alsojustis apreparedPartto theHomestayMasterMachine $ (PWD):/backup directory.

Recovery

The backup is also meant to be recoverable, otherwise the backup is meaningless. Docker recovery backup is also simple and requires only 2 parts.
First, create a container data1 with an empty data volume.

sudo docker run -itd -v /data --name data1 c9fc7f8eec37

Here you can see that the parameters of run can be written together. It was previously known that the parameter I was open in the container of stdin,t is to assign a pseudo terminal to the container. Here d is the background run, and the container ID container is printed.

Can be found, fame and fortune after the printing of the container ID, through the PS view, the container has been running.
Then, create another container, mount the data volumes in the Data1 container volume, and use Untar to extract the backup files to the mounted container volumes.

$(pwd):/backup c9fc7f8eec37 tar xvf /backup/backup.tar


At this time, the data from the previously backed up data volume container has been restored to the container data1. In order to view and verify the recovered data, we can then launch a container to mount the Data1 container volume to view.
In short, if you want to restore data to a container, first create a container with the data volume data1, then create another container, mount the Dbdata1 container, and use tar to extract the backup file to the mounted container volume.

Learn Docker:7 yourself. Backup and recovery of data volume containers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.