Data management for Docker

Source: Internet
Author: User
Tags docker run

In the process of using Docker, users often need to be able to view the data generated by the application in the container, or need to back up the data in the container, or even share the data between multiple containers, which inevitably involves the data management operation of the container.

There are two main ways in which you manage data in a container:

    • Data volumes

    • Data Volume container

First, the data volume

A data volume is a special directory that can be used by a container, bypassing the file system and providing many useful features:

    • Databases can be shared and reused between containers.

    • Changes to the data volume will take effect immediately.

    • Updates to the data volume do not affect mirroring.

    • The volume will persist until no container is used.

1. Create a data volume within the container

Use the-V flag to create a data volume within the container. Multiple data volumes can be created using the-v flag multiple times.

Docker run-d-P--name web-v/webapp jdeathe/centos-ssh

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/83/12/wKioL1dqLO_ByHibAAJiELT86Ck903.jpg "title=" Qq20160622141417.jpg "alt=" Wkiol1dqlo_byhibaajielt86ck903.jpg "/>

2. Mount a host directory as a data volume

Use the-V flag to specify that a local existing directory be mounted as a data volume in the container, for example, we mount the host's/home/webapp to the container's/mnt/webapp directory.

Docker run-d-P--name web-v/home/webapp:/mnt/webapp jdeathe/centos-ssh

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/83/13/wKiom1dqLp3AXhyWAAEuofWhHPs087.jpg "title=" Qq20160622142153.jpg "alt=" Wkiom1dqlp3axhywaaeuofwhhps087.jpg "/>

3. Mount the local host file as a data volume

If you mount a file directly to a container, using the file Editing tool may cause changes to the file inode.

Docker Run-ti-v/root/.bash_history:/root/.bash_history Jdeathe/centos-ssh/bin/bash

Synchronizes the command history of the container and the host.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/83/13/wKiom1dqMLzTNROzAACy8YUrmcM561.jpg "title=" Qq20160622142920.jpg "alt=" Wkiom1dqmlztnrozaacy8yurmcm561.jpg "/>

Second, the Data volume container

If users need to share some continuously updated data between containers, the simplest way is to use a data volume container. A data volume container is actually a generic container that is dedicated to providing data volumes for other containers to mount using the following methods.

First create a data volume container dbdata, and in which you create a data volume to mount to/dbdata:

Docker run-d--name dbdata-v/dbdata jdeathe/centos-ssh

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/83/14/wKiom1dqN0XirxMMAACyAD8myRw027.jpg "title=" Qq20160622145839.jpg "alt=" Wkiom1dqn0xirxmmaacyad8myrw027.jpg "/>

Then, you can use--volumes-from in other containers to mount the data volumes in the Dbdata container, we create DB1 and DB2 two containers, and mount the data volumes from the Dbdata container.

Docker run-d--name db1--volumes-from dbdata jdeathe/centos-sshdocker run-d--name DB2--volumes-from dbdata Jdeathe/ce Ntos-ssh

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/83/13/wKioL1dqOQiTnd1bAAFQQBMCOJ0817.jpg "title=" Qq20160622150629.jpg "alt=" Wkiol1dqoqitnd1baafqqbmcoj0817.jpg "/>

We can see that three containers share a single data volume, and everyone's data is synchronized. Other users can refer to their help documentation for testing.




This article is from the "Little Water Drop" blog, please make sure to keep this source http://wangzan18.blog.51cto.com/8021085/1791726

Data management for Docker

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.