-
-
Save divyang4481/7d27b2a3daa23874e4b86e7aaadebd23 to your computer and use it in GitHub Desktop.
docker (v1.11.1) quickstart terminal start.sh for hyper-v host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ---------------------------------------------------------------------------------------------------------------------\ | |
# Copyright (C) 2016 Doug Simmons | | |
# | | |
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance | | |
# with the License. | | |
# | | |
# You may obtain a copy of the License at | | |
# | | |
# http://www.apache.org/licenses/LICENSE-2.0 | | |
# | | |
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | | |
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | | |
# the specific language governing permissions and limitations under the License. | | |
# ---------------------------------------------------------------------------------------------------------------------/ | |
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 | |
STEP="Looking for powershell.exe" | |
if [ ! -z "$PSModulePath" ]; then | |
POWERSHELL="${PSModulePath}../powershell.exe" | |
STEP="Looking for hyper-v support" | |
"${POWERSHELL}" gvm &> /dev/null | |
if [ $? -eq 1 ]; then | |
echo "'powershell gvm' did not return 0" | |
exit 1 | |
fi | |
fi | |
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 | |
if [ ! -f "${POWERSHELL}" ]; then | |
echo "Could't find required Hyper-V components. Please setup Hyper-V." | |
exit 1 | |
fi | |
"${POWERSHELL}" gvm | 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 | |
echo ${DOCKER_MACHINE} | |
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 [ $# -eq 0 ]; then | |
echo "Start interactive shell" | |
exec "$BASH" --login -i | |
else | |
echo "Start shell with command" | |
exec "$BASH" -c "$*" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment