docker硬盘扩容脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker硬盘扩容脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#This script is dynamic modify docker container disk

if [ -z $1 ] || [ -z $2 ]; then
echo "Usage: container_name increase_capacity"
echo "Example: I want increase 11G to test"
echo "The command is: sh basename $0 test 11"
exit 1
fi
if [ docker inspect $1 &>>/dev/null && echo 0 || echo 1 -eq 1 ];then
echo "The container $1 is no exist!"
exit 1
fi
#container_id=docker inspect -f ‘{{ .Id }}‘ $1
container_id=docker inspect $1 | grep DeviceName | awk -F ‘"‘ ‘{print $4}‘
now_disk=dmsetup table /dev/mapper/$container_id|awk ‘{print $2}‘
disk=$(($2102410241024/512))
if [ $disk -lt $now_disk ];then
echo "I can‘t shink container $1 from $(($now_disk
512/1024/1024/1024))G to ${2}G!I only modify contanier increase disk!"
exit 1
fi
dmsetup table /dev/mapper/$container_id|sed "s/0 [0-9]* thin/0 $disk thin/"|dmsetup load /dev/mapper/$container_id
dmsetup resume /dev/mapper/$container_id
xfs_growfs /dev/mapper/$container_id
if [ $? -eq 0 ];then
echo "dynamic container $1 disk to ${2}G is success!"
else
echo "dynamic container $1 disk to ${2}G is fail!"
fi

以上是关于docker硬盘扩容脚本的主要内容,如果未能解决你的问题,请参考以下文章

Docker容器硬盘动态扩容

Docker容器学习梳理-容器硬盘热扩容

docker 容积硬盘扩容小坑一个

华为鲲鹏920云主机磁盘扩容脚本

安利:华为鲲鹏920云主机磁盘扩容脚本

openstack自动化搭建脚本