On my current team, we're still transitioning from Docker Toolbox to Docker Desktop for Windows. A lot of our scripts still assume that you're running Docker Toolbox on VirtualBox (like how to mount drives, how slashes or drive names work for those mounts).
Is there a reliable way to tell, from inside a script, whether docker
is coming from Docker Toolbox or Docker Desktop for Windows?
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.
#!/usr/bin/env bash
dockerIsToolBox() {
if [ "${DOCKER_TOOLBOX_INSTALL_PATH}" ];then
echo true
else
echo false
fi
}