Skip to content

Instantly share code, notes, and snippets.

@flaviodelgrosso
Last active June 7, 2024 16:11
Show Gist options
  • Save flaviodelgrosso/7292025efc5698ea8268084a977d0edf to your computer and use it in GitHub Desktop.
Save flaviodelgrosso/7292025efc5698ea8268084a977d0edf to your computer and use it in GitHub Desktop.
Install Docker engine in WSL
# Install Docker, you can ignore the warning from Docker about using WSL
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add your user to the Docker group
sudo usermod -aG docker $USER
sudo chmod 666 /var/run/docker.sock
# Install Docker Compose v2
sudo apt-get update && sudo apt-get install docker-compose-plugin
# Using Ubuntu 22.04 or Debian 10 / 11? You need to do 1 extra step for iptables
# compatibility, you'll want to choose option (1) from the prompt to use iptables-legacy.
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$VERSION_ID" = "22.04" ]; then
echo "Ubuntu 22.04 detected, installing iptables-legacy"
sudo apt-get install iptables-legacy
fi
fi
# Add the following to your .profile to ensure the Docker service runs in WSL 2
cat <<EOF >>$HOME/.profile
# Ensure the Docker Service Runs in WSL 2
if service docker status 2>&1 | grep -q "is not running"; then
wsl.exe -d "\${WSL_DISTRO_NAME}" -u root -e /usr/sbin/service docker start >/dev/null 2>&1
fi
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment