在我目前的团队中,我们仍在从Docker Toolbox过渡到Docker Desktop for Windows。我们的许多脚本仍然假设您在 VirtualBox 上运行 Docker Toolbox(例如如何挂载驱动器,斜杠或驱动器名称如何为这些挂载工作)。
有没有一种可靠的方法可以从脚本内部判断docker
是来自 Docker Toolbox 还是 Docker Desktop for Windows?
在我目前的团队中,我们仍在从Docker Toolbox过渡到Docker Desktop for Windows。我们的许多脚本仍然假设您在 VirtualBox 上运行 Docker Toolbox(例如如何挂载驱动器,斜杠或驱动器名称如何为这些挂载工作)。
有没有一种可靠的方法可以从脚本内部判断docker
是来自 Docker Toolbox 还是 Docker Desktop for Windows?
#!/usr/bin/env bash
dockerIsToolBox() {
if [ "${DOCKER_TOOLBOX_INSTALL_PATH}" ];then
echo true
else
echo false
fi
}
Toolbox works via docker-machine
. The way the docker
client is directed to the virtual machine is via a number of environment variables which you can see by running docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=/user/.docker/machine/machines/default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i
Docker for Mac connects directly to the /var/run/docker.sock
socket which is mapped into the Docker VM so this is easy to detect by the lack of environment variables.
I believe Docker for Windows uses a named pipe in the same way (//./pipe/docker_engine
) so you should also be able to tell by the lack of DOCKER_HOST
in the environment.
If Docker for Windows does still use the environment, there will be differences between the Toolbox and Docker for Windows variables. DOCKER_HOST
would be on a different range. DOCKER_CERT_PATH
won't include machine
etc.