DEV Community

0xkoji
0xkoji

Posted on • Edited on

Install Docker on WSL2

1. Install curl

First, ensure curl is installed on your system:

sudo apt install -y curl
Enter fullscreen mode Exit fullscreen mode

2. Install Docker via Shell Script

You can install Docker using a shell script from a GitHub repository:

curl -s https://raw.githubusercontent.com/karaage0703/ubuntu-setup/master/install-docker.sh | /bin/bash
Enter fullscreen mode Exit fullscreen mode

3. Manual Docker Installation Steps

If you prefer to install Docker manually, follow these steps:

Update Package Index

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install Prerequisite Packages

sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Enter fullscreen mode Exit fullscreen mode

Add Docker's Official GPG Key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode

Verify the GPG Key

sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Enter fullscreen mode Exit fullscreen mode

Update Package Index Again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install Docker Engine, CLI, and Containerd

sudo apt-get -y install docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode

Install Docker Compose Plugin

sudo apt-get -y install docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode

Add Your User to the Docker Group

sudo gpasswd -a $USER docker
Enter fullscreen mode Exit fullscreen mode

4. Start docker on WSL2

sudo service docker start
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
javieraguerocl profile image
Javier Aguero

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json": dial unix /var/run/docker.sock: connect: permission denied