如何在MacOS BigSur上访问Docker CE虚拟机? [英] How do I access the Docker CE virtual machine on MacOS BigSur?

查看:143
本文介绍了如何在MacOS BigSur上访问Docker CE虚拟机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MacOS BigSur(11.2.2)上运行Docker社区版本,并试图进入虚拟环境.

I'm running the Docker community edition on MacOS BigSur (11.2.2), and am trying to get into the virtual environment.

这篇文章说:做

$ screen〜/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

这一个从2020年2月开始说

and this one from February 2020 says

$屏幕〜/Library/Containers/com.docker.docker/Data/vms/0/tty

但是这些东西在我当前的安装中似乎都不起作用.

But neither of those things seem to work in my current install.

$ docker --version Docker 20.10.5版,内部版本55c4c88

推荐答案

找到的方法是 backdoors ,用于输入虚拟机,并且在发行版更改时它们也会更改,并且都提到了最新的Docker-for-mac不再支持这些方法.

The methods you have found are backdoors for entering in the virtual machine, and they change when the releases are changing, and both mentioned methods are no longer supported on the latest Docker-for-mac.

获得终端访问虚拟机的最典型方法(在虚拟机中创建一个 sh 进程并从中获取 tty ),您需要以下命令

The most canonical way to get terminal access to the virtual machine (create a sh process in the virtual machine and get tty from it), you need the following command.

docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh

此方法将创建一个容器并将其连接到主机的名称空间,此后它将在 init ( pid 1 ),方法是执行 nsenter 命令.在以后的版本中,这不会有太大变化,因为它依靠稳定的docker功能来访问虚拟机.在示例中,我使用了 debian ,但是您可以将其替换为具有 nsenter (例如 alpine busybox 等)

This approach will create a container and will join it to the namespace of the host, after which it will create a new shell in the namespace of the init (pid 1) by executing the nsenter command. This will not change much with the later releases since it relies on stabile docker features to get the access to the vm. In the example I had used debian, but you can replace this with any image that has nsenter (ex. alpine, busybox, etc.)

此外,您还可以通过当前的调试套接字进行访问,该调试套接字将直接在虚拟机中创建外壳并连接到该外壳.这更多是为调试而创建的 backdor ,在以后的版本中可能会删除/更改.

Also, you can get access trough the current debug socket which will create a shell directly in the virtual machine and connect to it. This is more a backdor created for debugging and might be removed/changed in future releases.

stty -echo -icanon && nc -U ~/Library/Containers/com.docker.docker/Data/debug-shell.sock && stty sane

这篇关于如何在MacOS BigSur上访问Docker CE虚拟机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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