docker-data volumes and data container volumes

Source: Internet
Author: User
Tags db2 docker run

There are two main ways of managing data in a container:

Data volume (volumes)

Data volume container (volumes dontainers)

Data volume

Use-V to mount a local directory into the container as a data volume.

[root@wls12c/]$ ls/b2b
backup  prog_update  wasStatus.log

[root@wls12c/]$ Docker run-d]--name=tomcat -v/b2b:/test-it centos/bin/bash
F85c616bde3317c857b657355561a1cfa4203fab2b8619386435e541089bde23
[ root@wls12c/]$ Docker exec-it tomcat/bin/bash
[root@f85c616bde33/]# ls/test
backup prog_update  WasStatus.log
[Root@f85c616bde33/]# Touch Test/demo
[Root@f85c616bde33/]# Ls/test
Backup Demo Prog_update WasStatus.log
[Root@f85c616bde33/]# exit
Exit
[ROOT@WLS12C/]$ ls/b2b
Backup Demo Prog_update WasStatus.log

You can see that the/B2B directory is already mounted in the container and has data in it.

Data Volume container

If the container needs to share some continuously updated data, the simplest way is to use the user Data volume container, which is a generic container that provides data volumes for other container mounts.

Create a data volume container dbdata

[ROOT@WLS12C/]$ Mkdir/dbdata
[root@wls12c/]$ Docker run-it-v/dbdata:/dbdata--name dbdata CentOS
[Root@07e4ad5587e1/]

Create the DB1 and DB2 two containers and use--volumes-from to mount the data volumes in the Dbdata container

[root@wls12c/]$ Docker run-it--volumes-from dbdata--name db1 centos
[root@wls12c/]$ Docker run-it--volumes-from Dbdata--name DB2 CentOS

Such three containers any one container is written in the directory, other containers can be seen.

Backup

Backs up the data in the Dbdata data volume container to the current directory of the host.

[root@wls12c/]$ Docker run--volumes-from dbdata-v $ (PWD):/backup--name worker CentOS Tar zcf/backup/backup.tar.gz/db Data
tar:removing leading '/' from member names
[root@wls12c/]$ ls
business-to-business            boot    Dev   lib         Media  net   root     SRV   tmp
backup.tar.gz  cgroup  etc   lib64       misc   opt   sbin     sys   usr
bin            dbdata  home  lost+found  mnt    proc  selinux  Test  var
[root@wls12c/]$ tar-tvf backup.tar.gz 
drwxr-xr-x root/root         0 2016-08-26 10:51 dbdata/
-rw-r--r--root/root         0 2016-08-26 10:40 dbdata/demo-rw-r--r--
root/root         6 2016-08-26 10:48 dbdata/test.txt
-rw-r--r--root/root         0 2016-08-26 10:51

Recovery

To create a container with a data volume

[root@wls12c/]$ Docker run-v/dbdata/dbdata--name db centos/bin/bash

Recovery

[root@wls12c/]$ Docker run--volumes-from db-v $ (PWD):/backup CentOS  tar xf/backup/backup.tar.gz

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.