Last active
October 10, 2022 16:02
-
-
Save yulken/8a04cbf5d40ad566fee08ef19b56d2a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# based on instructions found at https://dev.solita.fi/2021/12/21/docker-on-wsl2-without-docker-desktop.html | |
# remove old docker # | |
sudo apt remove docker docker-engine docker.io containerd runc | |
# configure package repository | |
sudo apt update | |
sudo apt install --no-install-recommends apt-transport-https ca-certificates curl -y | |
ID=$(grep "^ID=" /etc/os-release | cut -d "=" -f2) | |
VERSION_CODENAME=$(grep "^VERSION_CODENAME=" /etc/os-release | cut -d "=" -f2) | |
curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo apt-key add - | |
echo "deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list | |
sudo apt update | |
# install docker and add self to group | |
sudo apt install docker-ce docker-ce-cli containerd.io -y | |
sudo usermod -aG docker $USER | |
# configure dockerd | |
DOCKER_DIR=/mnt/wsl/shared-docker | |
mkdir -pm o=,ug=rwx "$DOCKER_DIR" | |
sudo chgrp docker "$DOCKER_DIR" | |
sudo mkdir /etc/docker | |
sudo bash -c 'cat << "EOF" >> /etc/docker/daemon.json | |
{ | |
"hosts": ["unix:///mnt/wsl/shared-docker/docker.sock"] | |
} | |
EOF' | |
# run dockerd automatically | |
bash -c 'cat << "EOF" >> $HOME/.profile | |
DOCKER_DISTRO=$WSL_DISTRO_NAME | |
DOCKER_DIR=/mnt/wsl/shared-docker | |
DOCKER_SOCK="$DOCKER_DIR/docker.sock" | |
export DOCKER_HOST="unix://$DOCKER_SOCK" | |
if [ ! -S "$DOCKER_SOCK" ]; then | |
mkdir -pm o=,ug=rwx "$DOCKER_DIR" | |
sudo chgrp docker "$DOCKER_DIR" | |
/mnt/c/Windows/System32/wsl.exe -d $DOCKER_DISTRO sh -c "nohup sudo -b dockerd < /dev/null > $DOCKER_DIR/dockerd.log 2>&1" | |
fi | |
EOF' | |
# Want to go passwordless with the launching of dockerd? | |
# All you need to do is | |
# sudo visudo | |
# %docker ALL=(ALL) NOPASSWD: /usr/bin/dockerd | |
# installing docker compose | |
COMPOSE_VERSION=1.29.2 | |
sudo curl -L "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment