Forum Discussion
How to write a script to start a Docker container and stop WSL safely when the container stops?
I don't know anything about Docker, but I can try and help with your first question (though not the second question about logging).
When you say that docker start fails, what does that look like? Is it just that nothing happens, or do you get a detailed error message?
If you put a large delay after the Start-Process (i.e. Start-Sleep -Seconds 20) and before the docker start, does the the docker start work then?
Do you know if the Docker desktop process spawns any child processes you can monitor for?
Knowing some of this may help us help you with the first question.
Cheers,
Lain
- ookerSep 05, 2023Copper Contributorwell, technically I can use sleep, but to learn more about scripting, is there a way to detect it when an event from a program happens? Say I open Word, is there a way to trigger a script when it finishes the startup?
- LainRobertsonSep 05, 2023Silver Contributor
There's no single, generic way to know that.
At best, there might be a way that's specific to the exact application/service you're working with, but for another application/service, it might require a completely different approach - or there may be no way at all. It's not like Windows prescribes a standard that client processes have to confirm to/integrate with.
Take Docker, for example. If the "Docker Desktop" you're launching were to in turn launch (or stop) child processes of its own, then you could leverage that behaviour. But let's say it doesn't, then you may have no visibility into how it's going with its start-up routine at which point all you can do is wait an arbitrary interval (or variations of that such as polling, but this isn't always materially any better).
Cheers,
Lain
- ookerSep 06, 2023Copper Contributor
I see. So if an app wants to implement this, what would be the way for it to do so? What teens should I look for?