脚本如何区分Docker Toolbox和Docker for Windows? [英] How can a script distinguish Docker Toolbox and Docker for Windows?

查看:178
本文介绍了脚本如何区分Docker Toolbox和Docker for Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的团队中,我们仍在从 Docker Toolbox 过渡到适用于Windows的Docker桌面.我们的许多脚本仍假定您在VirtualBox上运行Docker Toolbox(例如如何安装驱动器,斜杠或驱动器名称如何用于这些安装).

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).

是否有一种可靠的方法可以从脚本内部判断docker是来自Docker Toolbox还是适用于Windows的Docker Desktop?

Is there a reliable way to tell, from inside a script, whether docker is coming from Docker Toolbox or Docker Desktop for Windows?

推荐答案

工具箱通过docker-machine运行. docker客户端定向到虚拟机的方式是通过运行docker-machine env default

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

适用于Mac的Docker直接连接到映射到Docker VM的/var/run/docker.sock套接字,因此很容易通过缺少环境变量来检测.

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.

我相信适用于Windows的Docker以相同的方式(//./pipe/docker_engine)使用命名管道,因此您还应该能够通过环境中缺少DOCKER_HOST来判断.

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.

如果Docker for Windows仍然使用该环境,则Toolbox和Docker for Windows变量之间会有差异. DOCKER_HOST的范围将不同. DOCKER_CERT_PATH将不包含machine等.

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.

这篇关于脚本如何区分Docker Toolbox和Docker for Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆