How to automatically start docker in windows 10 without user login

I need to start docker containers when starting windows 10 pro without user logon.
Previously I was able to start “C:\Program Files\Docker\Docker\Docker Desktop.exe” with the Windows task scheduler application

Now after a new installation of windows it is not working.
Not even trying to start a powershell script that launches service and application.

Something starts and I notice it from the task manager but not the containers.

If I log in as a user, docker works fine

Thanks in advance for the help

2 Likes

I can’t answer, but I feel I should point out that Docker Desktop was made for development, so any way that works to start it automatically as you would start Docker on a server, could change and break the next day.

Despite that I see this goal a lot, so maybe someone know what changed.

Thanks for replying.
I also think that starting Docker automatically when the PC starts is a very common need. But nevertheless the help I find online (example: using Task Scheduler How to start Docker daemon (windows service) at startup without the need to log-in? - Stack Overflow to-log) that worked once, no longer work even with the PC with newly installed Windows.

1 Like

I’m actually curious why Windows users want to run Docker Desktop without user login. Can you help me to understand it? If there is a good reason, maybe even the developers can be convinced about it.

As I see currently, when Docker Desktop need to start automatically without a user login, that would mean it is not used for development and the features of Docker Desktop can’t be used. Maybe there are some extensions, but probably most of the tools that can be used as an extension could be used on Linux without a desktop. I mean those that don’t require user interaction. I could be wrong.

If Docker Desktop features are not used, I would try to run a virtual machine on Windows and install Docker CE in it. If you know the way to start hyperV machines or WSL on Windows 10 without user login, a VM could start and inside the VM, Docker CE would start automatically.

I haven’t tried it yet, but if we believe the instructions at the following link, it should work

1 Like

Thanks for the replies.
They are interesting but they are not the ones I need because I haven’t explained myself well and I’m trying to do it better.

On a PC with Windows 10 I use Docker to start some containers in which NextCloud All In One is present

https://nextcloud.com/it/blog/your-guide-to-nextcloud-all-in-one-on-windows-10-and-11/

The goal is that when the PC starts automatically from the bios in the morning, Docker and therefore NextCloud will also start, without having to access the PC to log in.

The first time I tried it, it worked by placing a task in Windows Task Scheduler that started “C:\Program Files\Docker\Docker\Docker Desktop.exe”.
The Apache server present in the containers was started and Nextcloud worked.

Now, by repeating the installation on the same machine, Task Scheduler, shortly after startup, executes “C:\Program Files\Docker\Docker\Docker Desktop.exe”, some processes are started, which I match with the task manager, but nextcloud doesn’t work, no active http service.

If I kill the active processes named docker with task manager and manually start C:\Program Files\Docker\Docker\Docker Desktop.exe” docker starts correctly.

I hope I have been clearer now and I apologize if I haven’t done so previously

Have you tried to start the task manually via the Windows Task Scheduler?

What exactly is set in the task?
Which user rights have been assigned?

But be warned, Docker Desktop and other graphical programs are not made for this. It could therefore be due to different versions alone.

And if it does run, it could break again. Rimelek’s suggested method is definitely the better choice.

But what about Docker containers? Have you checked in powershell whether containers are running or docker version can return the server version?

docker ps

and

docker version

Thanks for the right observation
Here is the result of the commands:
C:\Users\Eugenio>docker ps
request returned Internal Server Error for API route and version http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json, check if the server supports the requested API version

C:\Users\Eugenio>docker version
request returned Internal Server Error for API route and version http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version, check if the server supports the requested API version
Client:
Cloud integration: v1.0.35+desktop.5
Version: 24.0.6
API version: 1.43
Go version: go1.20.7
Git commit: ed223bc
Built: Mon Sep 4 12:32:48 2023
OS/Arch: windows/amd64
Context: default

and this is the situation when it runs correctly

C:\Users\Eugenio>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3ab938b897d nextcloud/aio-apache:latest “/start.sh /usr/bin/…” 3 months ago Up 2 hours (healthy) 80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:443->443/udp nextcloud-aio-apache
9ab527d8f3ef nextcloud/aio-notify-push:latest “/start.sh” 3 months ago Up 2 hours (healthy) nextcloud-aio-notify-push
94794f38abd0 nextcloud/aio-nextcloud:latest “/start.sh /usr/bin/…” 3 months ago Up 2 hours (healthy) 9000/tcp nextcloud-aio-nextcloud
750146d786c0 nextcloud/aio-imaginary:latest “imaginary -return-s…” 3 months ago Up 2 hours (healthy) nextcloud-aio-imaginary
58e51698bf53 nextcloud/aio-redis:latest “/start.sh” 3 months ago Up 2 hours (healthy) 6379/tcp nextcloud-aio-redis
ffc4794b0795 nextcloud/aio-postgresql:latest “/start.sh” 3 months ago Up 2 hours (healthy) 5432/tcp nextcloud-aio-database
15c1b938400d nextcloud/aio-talk:latest “/start.sh superviso…” 3 months ago Up 2 hours (healthy) 0.0.0.0:3478->3478/tcp, 0.0.0.0:3478->3478/udp nextcloud-aio-talk
885882f99a07 nextcloud/aio-collabora:latest “/start-collabora-on…” 3 months ago Up 2 hours (healthy) 9980/tcp nextcloud-aio-collabora
b54972c4ced8 nextcloud/all-in-one:latest “/start.sh” 3 months ago Up 2 hours (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:8443->8443/tcp, 9000/tcp nextcloud-aio-mastercontainer

If it can be useful I also did a test by running this script which also starts the service

start-service -Name com.docker.service
start “C:\Program Files\Docker\Docker\Docker Desktop.exe”

Then indeed, Docker is not running, not just the containers. That was just an idea, but as a mainly Linux and macOS user, I’m not the right person to help you solve this on Windows.


Please, format your posts according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```

The use case for me is for a build server. We have Windows 10 machines that have a GitLab Runner installed on them. Those runners use Docker to build software from source and test it. We have to run on Windows (not Linux) because we need to use Windows containers in some of the jobs.

Right now we have to log into the CI machine whenever the machine reboots. Furthermore, for systems running Windows containers, we have to wait for the UAC prompt to provide admin credentials for the special Docker Desktop for Windows service. This can be a pain if the machine reboots automatically (windows update, power outage, etc.).

Thank you for sharing your use case. I understand that you don’t want to buy a Windows server license, but from the point of view of Docker Inc, I don’t think GitLab runner would be a reason to support automatically start Docker Desktop, but that’s just my opinion.

Microsoft recommends Docker Desktop for Windows 10 and Windows 11, and they recommend Docker CE/Moby for Windows Server. Although there is no guide in Microsoft’s documentation to install Moby on Windows 10 (or I couldn’t find it), maybe you could build it as it is suggested here:

Note: According to the description, building Moby requires Docker Desktop, but you can stop that after building Moby.

And this is the documentation from Microsoft: Prepare Windows operating system containers | Microsoft Learn

@rimelek Thank you very much for those suggestions :+1: . I’m still somewhat new to Docker and Docker Desktop. If you’re saying there is another version of Docker that runs without login on Windows Server, then I will look into that. I’m mainly an engineer (not IT) so I wasn’t aware of every option available.

I apologize for the incorrect formatting of my messages.
But I’m also sorry that I haven’t found another user who has this trivial need to start Docker at startup without having to log in to the user.
I don’t despair of having suggestions on other forums (or docker support) to get this functionality working again.

Is the new task running in the context of the “SYSTEM” user or a user account that is a member of the “docker-users” group? Have you activated the “Run with highest privileges” option?

Which version of Docker Desktop and which WSL version was used compared to then and now?

task situation when it works


task situation when it starts by schedule but it does not works

Versione WSL: 2.0.9.0
Versione kernel: 5.15.133.1-1
Versione WSLg: 1.0.59
Versione MSRDC: 1.2.4677
Versione Direct3D: 1.611.1-81528511
Versione DXCore: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Versione di Windows: 10.0.19045.4170

Docker version 24.0.6, build ed223bc


thanks as always

1 Like

Sorry I also add the task scheduler history

Unfortunately, I still cannot see whether the user rights are set correctly in the Task Scheduler.
image
After clicking on OK you have to enter the user’s password.

But the situation is similar for me, even with correctly set user rights. So I tried a bit.

In my case, the distributions “docker-desktop” and “docker-desktop-data” for WSL 2 do not start.
So I also tried to start them via the Task Scheduler before Docker Desktop

C:\Windows\system32\wsl.exe -d docker-desktop
C:\Windows\system32\wsl.exe -d docker-desktop-data
C:\Program files\Docker\Docker\Frontend\Docker Desktop.exe

With the command “wsl -l -v” I could see that the distros were still stopped after starting Windows.
image
Therefore it does not work. Unfortunately I have no error message to find out why.

For this reason I have disabled WSL 2 in Docker Desktop.

Via the Task Scheduler I just started the program “C:\Program Files\Docker\Docker\Frontend\Docker Desktop.exe”

After that it worked for me.
I tested it with a web server running in a Docker container.

However, it should also be mentioned that the graphical user interface cannot be started if Docker Desktop has been started via the Task Scheduler, as it is already running in the background.

Normally, scheduled tasks run as background processes. However, according to the following instructions from Microsoft, you can set tasks to run interactively.

Unfortunately, this option is not available in the Windows Task Scheduler, but with the At Utility. But I don’t know if you can run a task on startup with the At Utility. Maybe someone can give me a hint.

It is also possible to import an XML file as a task into the Task Scheduler. Login to Windows with the user account that is a member of the “docker-users” group. Start the Task Scheduler and import the XML file. Change the user in the task to the same user who is logged in. After clicking on OK you have to enter the user’s password (not the Windows Hello PIN).

First of all, create an XML file with the name “Docker Desktop Autostart.xml” and the following content:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2024-04-02T07:27:45.4363167</Date>
    <Author>bluenobly</Author>
    <URI>\Docker Desktop Autostart</URI>
  </RegistrationInfo>
  <Triggers>
    <BootTrigger>
      <Enabled>true</Enabled>
    </BootTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-0-0-0-00000000-00000000-00000000-0000</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>"C:\Program files\Docker\Docker\Frontend\Docker Desktop.exe"</Command>
    </Exec>
  </Actions>
</Task>

TaskSettings: TaskSettings object - Win32 apps | Microsoft Learn

And don’t forget to deactivate WSL 2 in the Docker Desktop.

1 Like

Hi there, I have attempted the solutions from:

I’ve created the ps1 script and added:

start-service -Name com.docker.service
start “C:\Program Files\Docker\Docker\Docker Desktop.exe”

I’ve been unable to get the containers to start upon reboot.

Is there a recommended practice for running Docker containers on a Windows production environment? Our Linux containers are required to start as well on reboots without user login.

Thanks for the assistance.