shelbypereira
shelbypereira

Reputation: 2245

Run custom batch on windows once Docker daemon has started

I would like to run a custom script which sets up the docker network and starts a docker container (after setting up some directories). This script is slow so I would like it to run when my computer is starting up, but only AFTER the docker daemon is startup.

Following the instructions here Run Batch File On Start-up I can easily create a batch file and have it run on starutp, however I am currently getting the error:

docker network create --driver nat MY-net error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/networks/create: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

I am quite sure it is not related to privileges since running the script itself works.

Questions: Is it possible on windows batch file start to somehow run my batchfile last (after all other startup have been run, services/daemons are already started)?

Alternatively, is there some hook , which would let me run some custom script once the docker Daemon is up and running.

I am running Docker 19.0 on Windows 10. My docker is configured to be run on startup, and the daemon runs smoothly as I use docker regaulraly, so the issue seems to be that the script is beinf run before the docker daemon is fully started.

Upvotes: 2

Views: 753

Answers (2)

Markus-Hermann
Markus-Hermann

Reputation: 987

The answer from shelbypereira is a good lead. Thanks! However, it is only a lead. Allow me to add an actual script for doing the detection and reaction that has been asked for:

:search
TIMEOUT /T 1
call docker container ls

IF /I "%ERRORLEVEL%" NEQ "0" GOTO search

echo Found docker to be running due to exit code being 0.
call docker run awesome_autostart_stuff_or_something

Upvotes: 2

shelbypereira
shelbypereira

Reputation: 2245

Solution proposed by @gerhard works, basic solution is similar to this: https://superuser.com/questions/618210/how-to-make-a-batch-file-wait-for-a-process-to-begin-then-continue:

:search
REM CHECKING IF PROCESS IS RUNNING
tasklist|find "MyEXE"
IF %ERRORLEVEL% = 1 THEN (GOTO NOTfound)
TIMEOUT /T 1
GOTO search

:NOTfound
REM DO WORK

Upvotes: 2

Related Questions