github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/scripts/install_ddev_wsl2_docker_inside.ps1 (about) 1 # This PowerShell script tries to do almost all the things required to set up 2 # an Ubuntu WSL2 instance for use with DDEV and docker-ce installed inside WSL2. 3 # It requires that an Ubuntu wsl2 distro be installed already, preferably with `wsl --install`, but it can also be 4 # done manually. 5 # Run this in an administrative PowerShell window. 6 # You can download, inspect, and run this, or run it directly with 7 # Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; 8 # iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/ddev/ddev/master/scripts/install_ddev_wsl2_docker_inside.ps1')) 9 10 #Requires -RunAsAdministrator 11 12 # Make sure wsl is installed and working 13 if (-not(wsl -l -v)) { 14 throw "WSL2 does not seem to be installed yet; please install it with 'wsl --install'" 15 } 16 # Make sure default distro an ubuntu release 17 if (-not( wsl -e grep ^NAME=.Ubuntu //etc/os-release)) { 18 throw "Your installed WSL2 distro does not seem to be Ubuntu. You can certainly use DDEV with WSL2 in another distro, but this script is oriented to Ubuntu." 19 } 20 # Make sure using WSL2 21 if (-not (wsl -e bash -c "env | grep WSL_INTEROP=")) { 22 throw "Your default distro is not WSL version 2, please delete it and start over again" 23 } 24 if (-not(Compare-Object "root" (wsl -e whoami)) ) { 25 throw "The default user in your distro seems to be root. Please configure an ordinary default user" 26 } 27 # Install Chocolatey if needed 28 if (-not (Get-Command "choco" -errorAction SilentlyContinue)) 29 { 30 "Chocolatey does not appear to be installed yet, installing" 31 $ErrorActionPreference = "Stop" 32 Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 33 } 34 35 if (wsl bash -c "test -d /mnt/wsl/docker-desktop >/dev/null 2>&1" ) { 36 throw "Docker Desktop integration is enabled with the default distro and it must but turned off." 37 } 38 $ErrorActionPreference = "Stop" 39 # Install needed choco items; ddev/gsudo needed for ddev inside wsl2 to update hosts file on windows 40 choco upgrade -y ddev gsudo mkcert 41 42 mkcert -install 43 $env:CAROOT="$(mkcert -CAROOT)" 44 setx CAROOT $env:CAROOT; If ($Env:WSLENV -notlike "*CAROOT/up:*") { $env:WSLENV="CAROOT/up:$env:WSLENV"; setx WSLENV $Env:WSLENV } 45 46 wsl -u root bash -c "apt-get remove -y -qq docker docker-engine docker.io containerd runc >/dev/null 2>&1" 47 wsl -u root apt-get update 48 wsl -u root apt-get install -y ca-certificates curl gnupg lsb-release 49 wsl -u root install -m 0755 -d /etc/apt/keyrings 50 wsl -u root bash -c "rm -f /etc/apt/keyrings/docker.gpg && mkdir -p /etc/apt/keyrings && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg" 51 wsl -u root -e bash -c 'echo deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable | tee /etc/apt/sources.list.d/docker.list > /dev/null 2>&1' 52 53 wsl -u root -e bash -c "rm -f /etc/apt/keyrings/ddev.gpg && curl -fsSL https://pkg.ddev.com/apt/gpg.key | gpg --dearmor | tee /etc/apt/keyrings/ddev.gpg > /dev/null" 54 wsl -u root -e bash -c 'echo deb [signed-by=/etc/apt/keyrings/ddev.gpg] https://pkg.ddev.com/apt/ \* \* > /etc/apt/sources.list.d/ddev.list' 55 wsl -u root -e bash -c "apt update && apt install -y ddev docker-ce docker-ce-cli containerd.io wslu" 56 wsl -u root -e bash -c "apt-get upgrade -y >/dev/null" 57 wsl bash -c 'sudo usermod -aG docker $USER' 58 59 wsl bash -c 'echo CAROOT=$CAROOT' 60 wsl -u root mkcert -install 61 wsl -u root service docker start 62 if (-not(wsl -e docker ps)) { 63 throw "docker does not seem to be working inside the WSL2 distro yet. " 64 } 65 # If docker desktop was previously set up, the .docker can break normal use of docker client. 66 wsl rm -rf ~/.docker 67 68 refreshenv 69 70 wsl -u root -e bash -c "touch /etc/wsl.conf && if ! fgrep '[boot]' /etc/wsl.conf >/dev/null; then printf '\n[boot]\nsystemd=true\n' >>/etc/wsl.conf; fi" 71 72 wsl ddev version 73 74