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


# --- PRE-FLIGHT SETUP ---

BLUE='\033[1;34m'

GREEN='\033[0;32m'

NC='\033[0m'


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


# Helper to handle Windows/Unix pathing

win_to_unix_path(){ 

wd="$(pwd)"

cd "$1"

the_path="$(pwd)"

cd "$wd"

echo $the_path

}


# --- STEP 1: SELECT LOCATION ---

clear

echo -e "${BLUE}==================================================${NC}"

echo -e "${BLUE}     DOCKER TOOLBOX: STORAGE CONFIGURATION        ${NC}"

echo -e "${BLUE}==================================================${NC}"

echo ""

echo "Enter the drive and folder where Docker should live."

read -p "Target Path (Default: E:/docker): " USER_INPUT


# Use default if user just hits Enter

STORAGE_PATH="${USER_INPUT:-E:/docker}"


# Create directory if it doesn't exist

mkdir -p "$STORAGE_PATH"


# CRITICAL: These two variables force Docker Machine to use your E: drive

export MACHINE_STORAGE_PATH="$STORAGE_PATH"

export DOCKER_MACHINE_STORAGE_PATH="$STORAGE_PATH"


echo -e "Storage path locked to: ${GREEN}$MACHINE_STORAGE_PATH${NC}"

echo ""


# --- STEP 2: PATH & BINARY CHECKS ---

STEP="Setting up Environment Paths"

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


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

  echo "Error: Docker Machine or VirtualBox not found. Check your installation."

  exit 1

fi


# --- STEP 3: VIRTUALBOX GLOBAL OVERRIDE ---

# This forces the actual .vdi (Virtual Disk) to be stored on E: instead of C:

STEP="Configuring VirtualBox Default Folder"

"${VBOXMANAGE}" setproperty machinefolder "$MACHINE_STORAGE_PATH"


# --- STEP 4: MACHINE CREATION ---

"${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

  echo -e "${BLUE}Creating Machine '${VM}' in ${STORAGE_PATH}...${NC}"

  

  # Remove old remnants if any

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

  

  # Set proxy variables if they exist

  PROXY_ENV=""

  [ "${HTTP_PROXY}" ] && PROXY_ENV="$PROXY_ENV --engine-env HTTP_PROXY=$HTTP_PROXY"

  [ "${HTTPS_PROXY}" ] && PROXY_ENV="$PROXY_ENV --engine-env HTTPS_PROXY=$HTTPS_PROXY"

  [ "${NO_PROXY}" ] && PROXY_ENV="$PROXY_ENV --engine-env NO_PROXY=$NO_PROXY"


  # Create the machine

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

fi


# --- STEP 5: START & ENV SETUP ---

STEP="Checking status on $VM"

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

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

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

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

fi


STEP="Setting env"

eval "$("${DOCKER_MACHINE}" env --shell=bash --no-proxy "${VM}")"


# --- STEP 6: FINALIZE ---

STEP="Finalize"

clear

cat << EOF


                ##         .

          ## ## ##        ==

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

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

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

       \______ o           __/

         \    \         __/

          \____\_______/


EOF


echo -e "${BLUE}Docker${NC} is active at ${GREEN}$STORAGE_PATH${NC}"

echo -e "Machine IP: ${GREEN}$("${DOCKER_MACHINE}" ip ${VM})${NC}"

echo ""


# Wrapper function for docker.exe

docker () {

  MSYS_NO_PATHCONV=1 docker.exe "$@"

}

export -f docker


if [ $# -eq 0 ]; then

  exec "$BASH" --login -i

else

  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.*