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