First steps, you’ll need to install and configure WSL2. To install WSL2 you can use the Microsoft Store or follow these instructions: https://learn.microsoft.com/en-us/windows/wsl/install
Then to install Docker to run on Windows and WSL2 you’ll need to follow these instructions: https://docs.docker.com/desktop/wsl/
During some testing and trying to simplify my WSL2 environment I stumbled upon an annoying issue that prevented me from running docker ps
each time I attempted to run docker ps
I’d receive the following error.
1 |
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied |
To get around this issue you’ll need to run the following commands:
1 2 3 4 |
sudo adduser $USER docker newgrp docker sudo chown root:docker /var/run/docker.sock sudo chmod g+w /var/run/docker.sock |
Once those are ran you should be able to run docker without hitting permissions errors.
Those commands are adding/ensuring that the docker group exists and adding your existing user to the docker group. It then modifies the docker.sock to allow the docker group access to the socket.