Skip to content

Instantly share code, notes, and snippets.

@rlogiacco
Last active January 10, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlogiacco/fbaca7d8587e02c8e068fd3c3032ad94 to your computer and use it in GitHub Desktop.
Save rlogiacco/fbaca7d8587e02c8e068fd3c3032ad94 to your computer and use it in GitHub Desktop.
Docker 1.12 for Windows start script
#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT
VM=default
DOCKER_MACHINE=./docker-machine.exe
export PATH="/c/Program Files/Docker Toolbox:$PATH"
export HTTP_PROXY=10.235.34.235:3129
export HTTPS_PROXY=10.235.34.235:3129
for n in $(docker-machine ls --format {{.Name}}); do
NO_PROXY=$NO_PROXY,$(docker-machine ip $n)
done
export NO_PROXY=$NO_PROXY,localhost,127.0.0.1
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'
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
if [ $VM_EXISTS_CODE -eq 1 ]; then
"${DOCKER_MACHINE}" rm -f "${VM}" &> /dev/null || :
rm -rf ~/.docker/machine/machines/"${VM}"
"${DOCKER_MACHINE}" create -d virtualbox "${VM}"
fi
VM_STATUS="$(${DOCKER_MACHINE} status ${VM} 2>&1)"
if [ "${VM_STATUS}" != "Running" ]; then
"${DOCKER_MACHINE}" start "${VM}"
yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"
fi
eval "$(${DOCKER_MACHINE} env --shell=bash ${VM})"
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
echo -e "list images: ${GREEN}docker images${NC}"
echo -e "list running containers: ${GREEN}docker ps${NC}"
echo -e "list all container that were ever run: ${GREEN}docker ps -a${NC}"
echo -e "list container IDs: ${GREEN}docker ps -a -q${NC}"
echo -e "run a container: ${GREEN}docker run <image>${NC}"
echo -e "run a container (disconnected): ${GREEN}docker run -d <image>${NC}"
echo -e "run a container with name: ${GREEN}docker run --name=\"A name\"${NC}"
echo -e "execute a command within a running container: ${GREEN}docker exec -it <name> <command>${NC}"
echo -e "remove a container: ${GREEN}docker rm <containerId>${NC}"
echo -e "remove all non running containers: ${GREEN}docker rm \`docker ps -a -q\`${NC}"
echo -e "remove an image: ${GREEN}docker rmi <image-name>${NC}"
echo -e "redirect port (random): ${GREEN}docker run -P${NC}"
echo -e "redirect port: ${GREEN}docker run -P 8080:80${NC}"
echo -e "container ports list: ${GREEN}docker port <container-name>${NC}"
echo -e "set the hosting vm: ${GREEN}eval \"\$(docker-machine env <vm-name>)\"${NC}"
echo
echo -e "For exiting without stopping the container type: ${GREEN}^P^Q${NC}"
cd
docker () {
MSYS_NO_PATHCONV=1 docker.exe "$@"
}
export -f docker
exec "${BASH}" --login -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment