DEPRECATED, look at Start WSL 2 Service on Host startup instead.

I keep forgetting to start the docker service when opening up an instance of WSL(2)

Let’s fix that!

So what do we want to do?
We want to run the docker service from startup!
And that has to be done on sudo… but we don’t want to be reminded of that constantly
(in the form of a prompt to enter the sudo password on every WSL2 instance start).

First of all, sadly, we need to stop WSL from asking us for the sudo password.

Stop WSL2 from asking for sudo password

Next up, open up wsl and run

sudo service docker start > /dev/null 2>&1 &

This starts the service in the background while piping the output to null

As you opened a new WSL instance, this should be happening within your userprofile and opening up the .bashrc file.

Add following line to the end of the file:

sudo service docker start

Now WSL instance startup may take some seconds depending on how long it will take to start up docker in WSL.
Have fun!