Skip to content

Instantly share code, notes, and snippets.

@developerinlondon
Forked from alexproca/docker-machine-rename
Created December 13, 2017 10:34
Show Gist options
  • Save developerinlondon/2868dfc3c2790b6bba9eeec3376d5cd3 to your computer and use it in GitHub Desktop.
Save developerinlondon/2868dfc3c2790b6bba9eeec3376d5cd3 to your computer and use it in GitHub Desktop.
Rename docker-machine
#!/usr/bin/env bash
#copy this in a folder from path ex: /usr/local/bin
#usage: docker-machine-rename default my-default
OLD_MACHINE_NAME=${1:-default};
NEW_MACHINE_NAME=${2:-my-default-2};
STORE_PATH=`docker-machine inspect $OLD_MACHINE_NAME | grep -m 1 StorePath | cut -d ':' -f 2 | cut -c 3- | rev | cut -c 3- | rev`;
mv "$STORE_PATH/machines/$OLD_MACHINE_NAME" "$STORE_PATH/machines/$NEW_MACHINE_NAME";
cp "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json" "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json.bak"
sed -e "s/$OLD_MACHINE_NAME/$NEW_MACHINE_NAME/g" "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json.bak" > "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json";
vboxmanage modifyvm "$OLD_MACHINE_NAME" --name "$NEW_MACHINE_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment