Skip to content

Instantly share code, notes, and snippets.

@nicholasadamou
Created January 13, 2018 21:56
Show Gist options
  • Save nicholasadamou/2ed0fe353f7f14aaf7eedb4b76389e69 to your computer and use it in GitHub Desktop.
Save nicholasadamou/2ed0fe353f7f14aaf7eedb4b76389e69 to your computer and use it in GitHub Desktop.
With a couple of tweaks the WSL (Windows Subsystem for Linux, also known as Bash for Windows) can be used with Docker for Windows.
#!/bin/bash
# Docker configurations
# see: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
export DOCKER_HOST=tcp://0.0.0.0:2375 # Configure WSL to Connect to Docker for Windows
sudo mount --bind /mnt/c /c # Automatically set up the bind mount
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& source <(curl -s "https://raw.githubusercontent.com/nicholasadamou/bash-utils/master/utils.sh")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setting Up Docker for Windows and WSL to Work Flawlessly
# see: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
# Environment variables you need to set so you don't have to edit the script below.
DOCKER_CHANNEL=current #current|edge
DOCKER_COMPOSE_VERSION=1.16.1
install_dependencies() {
# Install packages to allow apt to use a repository over HTTPS.
declare -a PKGS=(
"apt-transport-https"
"ca-certificates"
"curl"
"software-properties-common"
)
for pkg in "${PKGS[@]}";
do
if ! package_is_installed "$pkg"; then
install_package "$pkg" "$pkg"
fi
done
}
install_docker_ce() {
# Add Docker's official GPG key.
execute \
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -" \
"Add Docker's official GPG key"
# Verify the fingerprint.
execute \
"sudo apt-key fingerprint 0EBFCD88" \
"Verify the fingerprint"
# Pick the release channel.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
${DOCKER_CHANNEL}" &> /dev/null
# Update the apt package index.
update
# Install the latest version of Docker CE.
install_package "docker-ce" "docker-ce"
}
install_docker_compose() {
# Install Docker Compose.
execute \
"sudo curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && \
sudo chmod +x /usr/local/bin/docker-compose" \
"docker compose (install)"
}
configure() {
# Allow your user to access the Docker CLI without needing root.
execute \
"sudo usermod -aG docker $USER" \
"Allow your user to access the Docker CLI without needing root"
if [ "$TRAVIS" != "true" ]; then
# Allow your user to bind a mount without a root password.
execute \
"sudo echo \"$USER ALL=(root) NOPASSWD: /bin/mount\" >> visudo" \
"Allow your user to bind a mount without a root password"
fi
}
print_in_purple "\n Docker\n\n"
install_dependencies
printf "\n"
install_docker_ce
printf "\n"
install_docker_compose
printf "\n"
configure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment