Skip to content

Instantly share code, notes, and snippets.

@gorvin
Last active May 8, 2018 23:22
Show Gist options
  • Save gorvin/e01766d6b2f25ac16362f9f6fb980fc6 to your computer and use it in GitHub Desktop.
Save gorvin/e01766d6b2f25ac16362f9f6fb980fc6 to your computer and use it in GitHub Desktop.
#
# This script installs and configures WSL to work with Docker Machine on Windows with VirtualBox.
# 1. Install WSL (check out [bowinstaller](https://github.com/xezpeleta/bowinstaller) for programmatic installation.
# 2. Run the contents of this script in Bash. (copy and paste works fine, no need to save)
#
sudo -sEH << 'EOM'
# Install the docker client and docker-compose
apt-get update && apt-get install -y curl ca-certificates
curl -sSL https://get.docker.com/ | sh
DOCKER_COMPOSE_VERSION="$(curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Add the current user to the docker group.
usermod -aG docker $(id -un)
# Symlink /c/ to /mnt/c/ as Docker Toolbox is expects /c/ path mappings.
[[ ! -e /c/ ]] && ln -s /mnt/c /
# docker-machine bash completion
DOCKER_MACHINE_VERSION="$(curl --silent "https://api.github.com/repos/docker/machine/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
base=https://raw.githubusercontent.com/docker/machine/${DOCKER_MACHINE_VERSION}/contrib/completion/bash
for i in docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
do
sudo wget "$base/${i}" -P /etc/bash_completion.d
done
source /etc/bash_completion.d/docker-machine-prompt.bash
EOM
#Set docker-machine to run on terminal start.
cat >> ~/.bashrc << 'EOM'
# Start the docker machine
export VBOX_MSI_INSTALL_PATH='/c/Program Files/Oracle/VirtualBox/'
# choco install -y docker-machine
# docker-machine.exe create -d virtualbox default
pushd '/c/ProgramData/chocolatey/bin/' > /dev/null
./docker-machine.exe start default || true
# Get env variables from docker-machine, convert paths, ignore comments, and strip double quotes.
$(./docker-machine.exe env --shell bash | sed 's/C:/\/c/' | sed 's/\\/\//g' | sed 's:#.*$::g' | sed 's/"//g' )
popd > /dev/null
# Change /mnt/c/ to /c/ in current working directory path
cd $(pwd | sed 's/\/mnt\/c\//\/c\//')
EOM
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment