Score:1

How can I tell when Docker Desktop has started in a PowerShell script?

je flag

I want to write a PowerShell script that will create a number of running docker containers on boot of the machine. The problem I'm running into is that despite the com.docker.service service running, the backend for Docker Desktop (I presume WSL2) is still getting ready.

I can manually recreate this behaviour by running docker version or similar when the system is starting. It will show:

error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json": open //./pipe/docker_engine: The system cannot find the file specified.

However after a couple of minutes (once the backend has come up) then the command will start working:

Client:
 Cloud integration: v1.0.22
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.10
 Git commit:        dea9396
 Built:             Thu Nov 18 00:42:51 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

How can I reliably wait for Docker Desktop to be ready before trying to start containers? I suspect the solution might be waiting for the pipe file or similar rather than a service.

cn flag
You could check the return code of a docker command in a loop (with a sleep) until you get a 0 back
je flag
@M_dk I'm far more familiar with Bash, am I right to assume that windows commands have exit codes like Bash commands do?
cn flag
Yeah, have a look at https://stackoverflow.com/questions/50200325/returning-an-exit-code-from-a-powershell-script
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.