Shared directory __docker share between Docker containers

Source: Internet
Author: User
Tags docker run

1, shared host directory to the container

Docker run-d--name=test-v/opt/test:/usr/databases docker-test
Test is the name of the container, it needs to be unique;-V indicates that a data volume is created and mounted in a container, and the example indicates that the/opt/test directory of the host is mounted to the container's/usr/databases directory; docker-test is the name of the mirror.

2, sometimes need to share the container of the volume, you need to use other ways to access

1) Adopt –volumes-from

The smallest mirror busybox can be used to help implement

1.docker Run--name=storedata-v/data:/usr/data busybox true
Defines a directory map called StoreData, which means that the/data directory of the host is mounted to the container's/usr/data directory. Other containers can be –volumes-from to use the directory

Docker run-d--name=test1--volumes-from storedata docker-test

Docker run-d--name=test2--volumes-from storedata docker-test

2 The different directories are mounted in the same directory by means of the LN link

Ln-s/data/opt/es1/

Ln-s/data/opt/es2/
The example generates a shortcut to the/data directory under both the/opt/es1/and/opt/es2/directories, so access to/opt/es1/data and/opt/es2/data are all/data directories

With the link, you can now map the directory directly with-V.

Docker run-d--name=test3-v/opt/es1/data:/usr/data docker-test

Docker run-d--name=test4-v/opt/es2/data:/usr/data docker-test
In this way, operating the/usr/data directory within the TEST3 and test4 containers is the/data directory of the operating host hosts

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.