How to access the VM created by docker's HyperKit?
Solution 1
Update 2019-01-31, thanks to ru10's update, now there is a better way:
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
Original Answer:
After a while, I found following way to get a shell of the VM that was created by HyperKit:
Run from terminal:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
You will see an empty screen, then type enter, you will get a login prompt. Login as , you will gett the shell:root
and hit enter, you will get a shell (no password)
To exit the session, type Ctrl-A k
(then y
to confirm).
It is a little bit hacky, but it seems to work for now (Sep 2016) (Sep 2017).
Solution 2
Mac OS High Sierra Docker version 18.06.0-ce-mac70 (26399)
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
instead of
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
Solution 3
According to this GitHub issue comment by a Docker maintainer, the recommended way to access the VM is through a privileged docker container.
Try logging into the VM: (I recommend this instead of using screen on the TTY)
$ docker run -it --privileged --pid=host justincormack/nsenter1
Solution 4
In fact, the answer from augurar is the only working as of 2021 as smammy says, the other options are deprecated.
So:
$ docker run -it --privileged --pid=host justincormack/nsenter1
was the right answer and worked for me in MacOS Big Sur as of July 2021.
Related videos on Youtube
Jifeng Zhang
Technical Lead & Configuration Manager Working with Architecture on AWS, programming with Java, Python, Bash and Linux Experienced in Teamcity, Jenkins, git, subversion Passionate about CI (continuous integration), CD (continuous delivery) and DevOps
Updated on July 29, 2021Comments
-
Jifeng Zhang almost 3 years
Docker for Mac uses a Linux VM created by HyperKit for storing and running containers on Mac.
With Docker Toolbox, I can just open VirtualBox and access the docker-machine VM. But with Docker for Mac, how do I access the VM created by HyperKit?
-
Gerry Gleason over 7 yearsThis is totally broken for me. I can connect, but something is deeply wrong with the TERM settings or how data is piped through. I get a non-functional terminal session that is losing data and not formatting right. I'm trying more ways to maybe reset the session, but failing so far.
-
Jauco over 7 yearsfor me it still works (feb-2017 1.13.0-beta39 using iterm2 terminal emulator)
-
Spencer Williams about 7 yearsThey need a better guide for this. I was able to follow your instructions and get into the VM. In my case, after pressing enter the first time, it simply took me to an
sh
prompt for the VM. When I ranls -l
on thattty
path, it turned out there was a link to it at/dev/ttys001
, which is much easier to type. -
Inanc Gumus about 7 yearsWhat can we do on this interface? I can't run node for example, I copied it somewhere else didn't work.
-
Inanc Gumus about 7 yearsOr does it enable me to connect to a network_mode=host container?
-
sapy almost 7 yearsJuly 2017 - Works ... Mac OS Sierra . Docker Version 17.06.0-ce-mac19 (18663)
-
Mahdi over 6 yearsSep '17: Doesn't work for me (Sierra 10.12.6). The command just outputs whatever I write until I press Ctrl-Z
-
Jifeng Zhang over 6 years@mahdix, if press enter, you will get a prompt. I have updated the instruction.
-
Mahdi over 6 years@JifengZhang If I press enter, cursor just moves to the next line. Nothing else happens. Until I press Ctrl-Z which returns me to my bash prompt.
-
Yongwei Wu about 6 years@GerryGleason If you, like me, connect to the TTY twice, the second screen session can cause all kinds of problems. In my case, I simply failed to quit the first session: I used Ctrl-A d, which only detached screen. I had to either use screen -r to restore the session, or quit the first session completely by Ctrl-A k.
-
Thiago Barcala about 6 years@GerryGleason I didn't know how to end the screen session, so I closed the terminal. When I connected for the second time, I had the exact same problem you described. I believe this happens because two screen sessions are trying to read from/write to the same tty. I was able to solve it by ending all the running screen sessions. To do so, reattach t the screen with
screen -r [screen id]
, then press CTRL a+k, confirm to kill the screen by pressing y. To find all the screens you have open usescreen -ls
. -
seren over 5 yearsThanks for the updated path. The accepted answer needs to be updated with this.
-
Rafael Eyng over 4 yearsWhat I don't understand: how come this VM doesn't have the command
docker
? -
demisx over 3 yearsHmm... I get "Cannot exec
~/Library/Containers/com.docker.docker/Data/vms/0/tty
Permission denied" error instead in MacOs Catalina and DFD v2.3.0.4 -
xenoterracide over 3 yearsthis works for me, accessing the tty in catalina did not
-
lqbweb over 3 yearsthis is due to a bug: github.com/docker/for-mac/issues/4822
-
smammy over 3 yearsThis should be in the accepted answer in 2021, since the
tty
link has gone away in recent versions of Docker Desktop. If you're leery of using a random image from an unverified publisher, this also works:docker run -it --rm --privileged --pid=host busybox nsenter -t1 -m -u -i -n
. -
smammy over 3 yearsThis no longer works in Docker Desktop 3.
-
smammy over 3 yearsThis no longer works in Docker Desktop 3.
-
parity3 about 3 yearsSomtimes the docker daemon is hosed and you need VM access to revive it.. In fact, this has been the only time so far in my dev where I've needed VM access.