Skip to content

Instantly share code, notes, and snippets.

@mkoertgen
Last active March 15, 2020 17:23
Show Gist options
  • Save mkoertgen/95272653fe95a336aba693902a5be752 to your computer and use it in GitHub Desktop.
Save mkoertgen/95272653fe95a336aba693902a5be752 to your computer and use it in GitHub Desktop.
Docker Toolbox Quickstart Terminal using Hyper-V Raw

Using Docker Toolbox on Windows with Hyper-V instead of Virtualbox

Unless you successfully signed up for Docker Beta you probably had trouble getting started with Docker Toolbox on Windows.

The typical issue is that the Docker Quickstart Terminal will refuse to start because Hyper-V is installed, cf. docker/toolbox #77. In fact this is related to Oracle VirtualBox 5.0 coming with the current Docker Tools release.

The usual advice is to just uninstall Hyper-V - which i consider a big deal, especially on Windows 10.

Some time ago, Scott Hanselman suggested a dual-boot workaround.

As some people already pointed out, it is perfectly ok to just use Docker with Hyper-V instead of VirtualBox.

The one thing missing for me was that i wanted the Docker Quickstart Terminal to just work.

So here is what you need to do after the Docker Toolbox installation:

  1. Uninstall VirtualBox (that came with Docker Toolbox)
  2. Adjust the startup.sh to use Hyper-V (according to this GIST)
  3. Create a Virtual Switch for Hyper-V
  4. Adjust the Docker Quickstart Terminal shortcut to run with administrator privileges (needed by Hyper-V)

Enjoy!

Once you are done with your docker session you might want to destroy the default boot2docker VM using either the Hyper-V Manager or simply

docker-machine.exe rm default

References:

#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong in step ´$STEP´... Press any key to continue..."' EXIT
VM=${DOCKER_MACHINE_NAME-default}
DOCKER_MACHINE=./docker-machine.exe
BLUE='\033[1;34m'
GREEN='\033[0;32m'
NC='\033[0m'
if [ ! -f "${DOCKER_MACHINE}" ]; then
echo "Docker Machine is not installed. Please re-run the Toolbox Installer and try again."
exit 1
fi
"${DOCKER_MACHINE}" ls | grep \""${VM}"\" &> /dev/null
VM_EXISTS_CODE=$?
set -e
STEP="Checking if machine $VM exists"
if [ $VM_EXISTS_CODE -eq 1 ]; then
"${DOCKER_MACHINE}" rm -f "${VM}" &> /dev/null || :
rm -rf ~/.docker/machine/machines/"${VM}"
#set proxy variables if they exists
if [ -n ${HTTP_PROXY+x} ]; then
PROXY_ENV="$PROXY_ENV --engine-env HTTP_PROXY=$HTTP_PROXY"
fi
if [ -n ${HTTPS_PROXY+x} ]; then
PROXY_ENV="$PROXY_ENV --engine-env HTTPS_PROXY=$HTTPS_PROXY"
fi
if [ -n ${NO_PROXY+x} ]; then
PROXY_ENV="$PROXY_ENV --engine-env NO_PROXY=$NO_PROXY"
fi
"${DOCKER_MACHINE}" create -d hyperv $PROXY_ENV "${VM}"
fi
STEP="Checking status on $VM"
VM_STATUS="$(${DOCKER_MACHINE} status ${VM} 2>&1)"
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 ${VM})"
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
docker () {
MSYS_NO_PATHCONV=1 docker.exe "$@"
}
export -f docker
# if you are behind a corporate proxy, exclude DOCKER_HOST
#export NO_PROXY=$(docker-machine ip default)
if [ $# -eq 0 ]; then
echo "Start interactive shell"
exec "$BASH" --login -i
else
echo "Start shell with command"
exec "$BASH" -c "$*"
fi
@mkoertgen
Copy link
Author

Alternatively,

Reasons to not use Hyper-V? You probably work in a company network with an old Kaspersky installation (before 15 M2). The Kaspersky NDIS6 Filter is known for not working together with Hyper-V

@mkoertgen
Copy link
Author

mkoertgen commented May 4, 2016

In case you are behind a corporate proxy, you will probably get

An error occurred trying to connect: Post https://192.168.99.100:2376/v1.21/containers/create: Forbidden

when talking to the docker host. To resolve this you need to exclude your DOCKER_HOST ip from proxying by

# if you are behind a corporate proxy, exclude DOCKER_HOST
export NO_PROXY=$(docker-machine ip default)

I just added this to start.sh, cf. commit https://gist.github.com/mkoertgen/95272653fe95a336aba693902a5be752/revisions#diff-d0b2ef35f4d7cb0284dd5cf566b62f51R75

Thx to How to install Docker on Windows behind a proxy.

Sidenote: proxies cause much overhead!

@yeasin90
Copy link

Followed the steps. So far worked nicely!

Always getting this when running the terminal.
docker-terminal

Any suggestions?

@mkoertgen
Copy link
Author

Hi @yeasin90, if possible for you i would recommend to go with Docker Desktop which is far less problematic than Docker Toolbox.

Other than that, it seems the VM either gets stuck booting or the networking got messed up. Try check using the Hyper-V Manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment