Skip to content

Instantly share code, notes, and snippets.

@swamibluedata
Last active July 22, 2016 17:49
Show Gist options
  • Save swamibluedata/509230a3d706c38c62c8784a249523fd to your computer and use it in GitHub Desktop.
Save swamibluedata/509230a3d706c38c62c8784a249523fd to your computer and use it in GitHub Desktop.
# Set the container name here
INSTANCE_NAME="bluedata-12"
# Get the actual device mapper pool use by docker
POOL=$(docker info | grep pool | awk '{print $3}')
DEVMAPPER_POOL="/dev/mapper/$POOL"
DEV="$INSTANCE_NAME-dev"
# Get the container id of the instance
CONT_ID=$(docker inspect -f {{.Id}} $INSTANCE_NAME)
# Stop the container
docker stop $INSTANCE_NAME
# Recreate the device based on the size and device id from the docker metadata
METADATA_FILE="/var/lib/docker/devicemapper/metadata/$CONT_ID"
SIZE=$(cat $METADATA_FILE | python -c "import json,sys;obj=json.load(sys.stdin);print obj['size']")
DEVICE_ID=$(cat $METADATA_FILE | python -c "import json,sys;obj=json.load(sys.stdin);print obj['device_id']")
dmsetup create "$DEV" --table "0 $(($SIZE / 512)) thin $DEVMAPPER_POOL $DEVICE_ID"
e2fsck -f /dev/mapper/$DEV
dmsetup remove "$DEV"
echo "Do instance reboot of this node"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment