How can I dynamically bind a Volume group to a running Docker container and dynamically add Volume ?, Dockervolume

Source: Internet
Author: User

How can I dynamically bind a Volume group to a running Docker container and dynamically add Volume ?, Dockervolume

How can I dynamically bind a Volume group to a running Docker container and dynamically add Volume?

Requirement: mount the/tmp/test directory of the physical machine to the/src directory of the running container test (test container id: 955138b6c3ed ).

Code: dynamic_mount_docker_volume

#! /Bin/bash # This script is dynamic mount docker volumens # Author Deng Leiif [-z $1] | [-z $2] | [-z $3]; then echo "Usage: container_name physics_volumes container_volumes" echo "Example: I want mount physics/tmp/test to container/src in test" echo "The command is: bash 'basename $ 0' test_container_id/tmp/test/src "exit 1 fiwhich nsenter & >>/dev/nullif [$? -Ne 0]; then echo "plsease install nsenser, command is: yum install util-linux" exit 1 fiset-eCONTAINER = $1 HOSTPATH = $2 CONTPATH = $ 3if [! -D $ HOSTPATH]; then echo "physics $ HOSTPATH is not exist! "Exit 1 fiREALPATH = $ (readlink -- canonicalize $ HOSTPATH) FILESYS = $ (df-P $ REALPATH | tail-n 1 | awk '{print $6 }') while read dev mount junk do [$ MOUNT = $ FILESYS] & [$ DEV! = "Rootfs"] & break done usage:
$ chmod +x dynamic_mount_docker_volume $ docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter $ ./dynamic_mount_docker_volume 955138b6c3ed /tmp/test /src 

Instructions for use:

Grant the executable permission to dynamic_mount_docker_volume.

Execute the script to mount the volume to the running container

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.