Hello,
I’m currently running Docker Desktop on Windows 11, using an Ubuntu LTS VM through WSL2.
It is properly integrated with Docker Desktop, and functions as expected.
I deployed a Portainer container for WSL2 within Ubuntu following their documentation and it works as expected.
I made sure the container has the flag “always” to always start after reboot, I even did it in different ways, by using the terminal directly and by using Portainer itself to set the flag.
Yet when I reboot the Windows machine, the container won’t start. Docker Desktop is properly set to start with windows, but the container won’t.
I tried to do this within the Ubuntu distro recommended by the AI:
sudo nano /etc/init.d/start-portainer
#!/bin/bash
sleep 40
docker start portainer
sudo chmod +x /etc/init.d/start-portainer
sudo update-rc.d start-portainer defaults
But it did not work.
I then tried with cronjobs:
@reboot sleep 30 && docker start portainer
And this, of course, worked perfectly. But as far as Im aware cronjobs shouldnt be the ideal solution for this, right? Specially since I will be using more containers that need to start right away.
What am I doing wrong? I feel like this is related to WSL2 setup specifically, since all the information available is as easy as to set the correct flag to the portainer, which i already did, but I cant find anything regarding WSL2 specifically so I don’t know what Im missing or doing wrong
Thats because there’s already a restart policy, as I stated in the post I already made sure that the container has the “–restart always” flag set, i did it both by terminal and then by confirming through Portainer itself that the flag is indeed set, even the AI acknowledges this, yet it does not work for whatever reason. Should it work just like that even with WSL2? Because if that’s the case then I don’t know what’s wrong
When I create a test container like this (regardless whether the command is executed on the Windows host, or in a WSL2 distro with enabled Docker Deskop integration:
docker run -d -p 8080:80 --name restart-test --restart always nginx
Then quit Docker Desktop and restart it again: the container is running.
Then reboot Windows without stopping Docker Desktop, Login after restart, start Docker Desktop: the container is running.
Are you sure the wsl distribution only uses the docker cli and engine provided by Docker Desktop’s wsl integration?
Yes, it is an Ubuntu LTS WSL2 distribution, sorry, I assumed it was a VM.
I executed the commands through powershell directly, and Docker Desktop is correctly integrated with WSL, while my Ubuntu distro is also set as default to avoid the use of docker-desktop distro.
However, I’ve decided to nuke the whole setup and start from scratch, things are working as intended now
The docker desktop backend which provides the docker engine will always run in the docker-desktop distro.
WSL integration just makes the docker cli binaries available in enabled distributions, and sets the docker sock access so that its possible to access the docker engine in the docker-desktop distribution without having to configure anything additionally.