Docker Data Management

Source: Internet
Author: User
Tags unpack docker ps docker run

1. Mount the local directory into the container

# docker run-itd-v/data/:/data1/centos bash//-v used to specify mount directory,/data/to local directory,/data1/as directory in container

2. Mount the data volume

Mount the directory, you can specify the name of the container, if not specified randomly defined, such as we did not specify above, he generated a container named Angry_ritchie, the name can be used in Docker PS to see, the right column is

# docker RUN-ITD--volumes-from Angry_ritchie (container's name) CentOS Bash

This creates a new container using the CentOS image and uses the data volumes of the Angry_ritchie container

3. Define Data Volume container

Sometimes we need to share data between multiple containers, similar to NFS in Linux, so we can build a dedicated data volume container, and then other containers will overload the data volume directly:

Creating a Data Volume container

# docker run-itd-v/data/--name fansik CentOS Bash//Note here/data/is the/data directory of the container, not the local/data/directory

Then let the other container mount the data volume

# docker RUN-ITD--volumes-from Fansik--name=zhangsan CentOS Bash

The Fansik container is equivalent to the NFS server, and all the data is stored on the Fansik mirror (so Fansik cannot stop rebooting, etc.)

4. Backup of data volumes

To create backup directory backups:

# mkdir Backup

Create a container using Fansik and mount the backup directory to a container

# docker RUN-ITD--volumes-from fansik-v/backup/:/backup/centos Bash

Enter the container and you'll see a backup directory with the data directory under the root directory.

# Docker exec-it 5A4 Bash

Package The data directory and put it in the backup directory so you can see the data we backed up in the host's backup.

# Tar Cvf/backup/data.tar data

5. Recovery of data volumes

I have removed all the other containers before I recover, just want to use the previous container name

First create a data volume container, build a new container and mount the data volume container, then unpack the tar package

New Data Volume Container:

# docker Run-itd-v/data--name fansik CentOS Bash

Mount the data volume to create a new container, and unpack the package:

# Docker Run--volumes-from fansik-v/backup/:/backup CentOS tar Xvf/backup/data.tar

When this command executes, it exits.

Docker Data Management

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.