从批处理文件 (Windows) 启动 Docker 桌面和 Docker 堆栈
Start Docker Desktop and a Docker stack from a batch file (Windows)
如何从 Windows 批处理文件启动 Docker 服务、Docker Swarm 和 Docker 桌面?
我创造了各种变体,例如:
@echo off
echo "[1] Start Docker Desktop ... "
start /B "C:\Program Files\Docker\Docker\Docker Desktop.exe"
echo "[2] Waiting for Docker to accept commands ... "
timeout /t 20
:repeat
docker ps -a >> output.txt || ( timeout /t 10 && goto :repeat; )
echo " ... Docker started ... "
timeout /t 5
echo "[3] Starting a Docker Stack (Swarm) ... "
cd \a-docker-compose-folder
docker stack deploy -c docker-compose.yml devhome
echo " ... Docker Swarm started ... "
当我不使用“start /B”时,批处理文件正在启动桌面(和服务)但一直在等待。因此,它不会启动(当然)下一个命令。
另一种选择是启动 docker 服务,但我找不到 dockerd.exe。然后启动 Docker Swarm ... 最后是 Docker 桌面。
实现这个很简单:
- 创建一个文件,在本例中为 'docker-polling-start-postgres-swarm.bat',用于轮询和启动...
@echo off
echo "[1] Starting a Docker Swarm with Postgres ... "
:repeat
docker ps -a > output.txt || ( timeout /t 5 && goto :repeat; )
echo " ... Docker started ... "
timeout /t 5
echo "[2] Starting a Docker Swarm with Postgres ... "
docker stack deploy -c docker-compose.yml devhome
echo " ... Docker Swarm started ... "
- 创建主批处理文件,首先在后台启动上述文件,然后在前台启动 Docker 桌面。您仍然可以准确地看到批处理文件输出中发生了什么!
@echo off
echo "[1] Start-and-poll Docker Swarm in the background till it can be started... "
start /B docker-polling-start-postgres-swarm.bat
echo "[2] Start Docker EE in the background ... "
"C:\Program Files\Docker\Docker\Docker Desktop.exe"
set /p id="Finish"
我在桌面上创建了一个简单的快速 link。只需单击快速 link 即可开始所有操作。享受吧!
如何从 Windows 批处理文件启动 Docker 服务、Docker Swarm 和 Docker 桌面?
我创造了各种变体,例如:
@echo off
echo "[1] Start Docker Desktop ... "
start /B "C:\Program Files\Docker\Docker\Docker Desktop.exe"
echo "[2] Waiting for Docker to accept commands ... "
timeout /t 20
:repeat
docker ps -a >> output.txt || ( timeout /t 10 && goto :repeat; )
echo " ... Docker started ... "
timeout /t 5
echo "[3] Starting a Docker Stack (Swarm) ... "
cd \a-docker-compose-folder
docker stack deploy -c docker-compose.yml devhome
echo " ... Docker Swarm started ... "
当我不使用“start /B”时,批处理文件正在启动桌面(和服务)但一直在等待。因此,它不会启动(当然)下一个命令。
另一种选择是启动 docker 服务,但我找不到 dockerd.exe。然后启动 Docker Swarm ... 最后是 Docker 桌面。
实现这个很简单:
- 创建一个文件,在本例中为 'docker-polling-start-postgres-swarm.bat',用于轮询和启动...
@echo off echo "[1] Starting a Docker Swarm with Postgres ... " :repeat docker ps -a > output.txt || ( timeout /t 5 && goto :repeat; ) echo " ... Docker started ... " timeout /t 5 echo "[2] Starting a Docker Swarm with Postgres ... " docker stack deploy -c docker-compose.yml devhome echo " ... Docker Swarm started ... "
- 创建主批处理文件,首先在后台启动上述文件,然后在前台启动 Docker 桌面。您仍然可以准确地看到批处理文件输出中发生了什么!
@echo off echo "[1] Start-and-poll Docker Swarm in the background till it can be started... " start /B docker-polling-start-postgres-swarm.bat echo "[2] Start Docker EE in the background ... " "C:\Program Files\Docker\Docker\Docker Desktop.exe" set /p id="Finish"
我在桌面上创建了一个简单的快速 link。只需单击快速 link 即可开始所有操作。享受吧!