Log: Docker Toolbox Storage Relocation (C: to E:)

admin
By -
0

 If you  had any little knowledge to bash script then you  can do this by yourself ,though i took  the help of gemini for this cause i was on hurry

docker toolbox start.sh  override to  chnage vm and virtual  machine and virtual  disk  volume and space to  another drive drive E/docker 

 How to Reconfigure and Override Docker Toolbox to a Custom Storage Location.



# start.sh

#!/bin/bash


trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong in step ´$STEP´... Press any key to continue..."' EXIT


# Prompt the user for the folder location or default to E:/ with .docker

#read -p "Enter Docker folder location (press Enter to default to E:/): " FOLDER

#FOLDER="${FOLDER:-E:/}"


# Set path for .docker folder

#DOCKER_FOLDER="${FOLDER}/.docker"


# Quick Hack: used to convert e.g. "C:\Program Files\Docker Toolbox" to "/c/Program Files/Docker Toolbox"

win_to_unix_path() {

    wd="$(pwd)"

    cd "$1"

    the_path="$(pwd)"

    cd "$wd"

    echo $the_path

}


# This is needed to ensure that binaries provided

# by Docker Toolbox over-ride binaries provided by

# Docker for Windows when launching using the Quickstart.

export PATH="$(win_to_unix_path "${DOCKER_TOOLBOX_INSTALL_PATH}"):$PATH"

VM=${DOCKER_MACHINE_NAME-default}

DOCKER_MACHINE="${DOCKER_TOOLBOX_INSTALL_PATH}\docker-machine.exe"


STEP="Looking for vboxmanage.exe"

if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then

  VBOXMANAGE="${VBOX_MSI_INSTALL_PATH}VBoxManage.exe"

else

  VBOXMANAGE="${VBOX_INSTALL_PATH}VBoxManage.exe"

fi


BLUE='\033[1;34m'

GREEN='\033[0;32m'

NC='\033[0m'


# Clear all_proxy if not socks address

if [[ $ALL_PROXY != socks* ]]; then

  unset ALL_PROXY

fi

if [[ $all_proxy != socks* ]]; then

  unset all_proxy

fi


if [ ! -f "${DOCKER_MACHINE}" ]; then

  echo "Docker Machine is not installed. Please re-run the Toolbox Installer and try again."

  exit 1

fi


if [ ! -f "${VBOXMANAGE}" ]; then

  echo "VirtualBox is not installed. Please re-run the Toolbox Installer and try again."

  exit 1

fi


"${VBOXMANAGE}" list vms | grep \""${VM}"\" &> /dev/null

VM_EXISTS_CODE=$?


set -e


STEP="Checking if machine $VM exists"

if [ $VM_EXISTS_CODE -eq 1 ]; then


  # Prompt the user for the folder location or default to E:/ with .docker

  read -p "Enter Docker folder location (press Enter to default to E:/): " FOLDER

  FOLDER="${FOLDER:-E:/}"


  # Set path for .docker folder

  DOCKER_FOLDER="${FOLDER}/.docker"


  echo "VM does not exist. Creating new machine..."

  "${DOCKER_MACHINE}" rm -f "${VM}" &> /dev/null || :

  rm -rf "${DOCKER_FOLDER}/machine/machines/${VM}"

  # Set proxy variables inside virtual docker machine if they exist in host environment

  if [ "${HTTP_PROXY}" ]; then

    PROXY_ENV="$PROXY_ENV --engine-env HTTP_PROXY=$HTTP_PROXY"

  fi

  if [ "${HTTPS_PROXY}" ]; then

    PROXY_ENV="$PROXY_ENV --engine-env HTTPS_PROXY=$HTTPS_PROXY"

  fi

  if [ "${NO_PROXY}" ]; then

    PROXY_ENV="$PROXY_ENV --engine-env NO_PROXY=$NO_PROXY"

  fi


  echo "Creating Docker Machine..."

  "${DOCKER_MACHINE}" create -d virtualbox $PROXY_ENV "${VM}"


  if [ $? -ne 0 ]; then

    echo "Error creating Docker Machine. Checking logs..."

    exit 1

  fi

fi


STEP="Checking status on $VM"

VM_STATUS="$( set +e ; "${DOCKER_MACHINE}" status "${VM}" )"

if [ "${VM_STATUS}" != "Running" ]; then

  echo "Machine is not running, starting it..."

  "${DOCKER_MACHINE}" start "${VM}"

  echo "Regenerating certificates..."

  yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"

fi


STEP="Setting env"

echo "Setting Docker environment variables..."

eval "$("${DOCKER_MACHINE}" env --shell=bash --no-proxy "${VM}" | sed -e "s/export/SETX/g" | sed -e "s/=/ /g")" &> /dev/null # For persistent Environment Variables, available in next sessions

eval "$("${DOCKER_MACHINE}" env --shell=bash --no-proxy "${VM}")" # For transient Environment Variables, available in current session


STEP="Finalize"

clear

cat << EOF



                        ##         .

                  ## ## ##        ==

               ## ## ## ## ##    ===

           /"""""""""""""""""\___/ ===

      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~

           \______ o           __/

             \    \         __/

              \____\_______/


EOF

echo -e "${BLUE}docker${NC} is configured to use the ${GREEN}${VM}${NC} machine with IP ${GREEN}$("${DOCKER_MACHINE}" ip ${VM})${NC}"

echo "For help getting started, check out the docs at https://docs.docker.com"

echo


#cd #Bad: working dir should be whatever directory was invoked from rather than fixed to the Home folder

docker () {

  MSYS_NO_PATHCONV=1 docker.exe "$@"

}

export -f docker


if [ $# -eq 0 ]; then

  echo "Start interactive shell"

  exec "$BASH" --login -i

else

  echo "Start shell with command"

  exec "$BASH" -c "$*"

fi

The goal of this modification was to move the entire Docker environment out of the system drive. Here is the description of what the script now does and the reasoning behind it:

Establishing User-Defined Storage

By default, Docker Toolbox is designed to be "plug-and-play," which means it automatically creates everything in your Windows User Profile. This is convenient for the software but bad for your C: drive space. We modified the script to introduce a Path Variable. This serves as a new "base of operations." By setting this at the very beginning, every subsequent action—like creating security keys or downloading the operating system—is forced to happen inside your chosen folder on the E: drive.

Reconfiguring the VirtualBox Engine

Docker doesn't run directly on Windows; it runs inside a Virtual Machine managed by VirtualBox. Even if you tell Docker to stay on the E: drive, VirtualBox usually tries to save its heavy virtual disks (the .vdi files) back on the C: drive. We added a specific instruction to the script that talks to the VirtualBox Engine before the machine is even created. This "re-anchors" the default storage folder, ensuring the massive virtual hard drives are physically stored on your larger drive.

Ensuring Location Persistence

The original script's logic is often "blind" to external drives. If it doesn't see a machine on the C: drive, it might try to create a new one, wasting time and space. We modified the script to be Location-Aware. It now performs a check at your specific custom path first. This ensures that the script recognizes your existing work on the E: drive and simply resumes the session rather than starting from scratch.

Why This Was Necessary

Without these modifications, Docker Toolbox acts like a tenant that moves into your house without asking and fills the smallest room (your C: drive) with heavy boxes. By modifying the start.sh script, we effectively gave Docker a "moving notice," providing it with a much larger "warehouse" on the E: drive where it can grow without slowing down your operating system.

Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*