How to start docker when you start WSL

Dmytro Zhluktenko
2 min readSep 26, 2021

Recently, I made a video on How to replace Docker Desktop on Windows with Portainer. Once I shot it, I figured out that Docker for Desktop allowed you to boot docker engine on startup. I also want to enable this ability with the approach I proposed, so this article is meant to enable this feature.

First, you have to acknowledge that you can’t just run systemctl in WSL — there is no support for it yet. Even though, it would be a very correct way of doing it in normal Linux environment.

Next thing, we figure out we can start docker by using a command:

sudo service docker start

Great, now we have to run it each time we run WSL. This could be achieved by adding the

sudo service docker status || sudo service docker start

into the .profile file in your WSL directory. What this line does is checking whether docker is already running, and starts docker is not running yet. The only question remains — where is .profile which is being ran each time you start WSL?!

Go to /home/<username> from your WSL, and type

explorer.exe .

— this will take us to Windows File Explorer to the folder which contains the .profile file.

Next, we can add the line into .profile using Notepad++ or text edit program of your choice.

Click save, restart and voilà! You now have the docker engine booted at the start of WSL terminal!

--

--

Dmytro Zhluktenko

Ukraine, Lviv. Young & mad. IT, .NET, F#, C#, Azure, software developer. Leading @lvivdotnet. Traveling, seeing things, living life.