How to access the VM created by docker's HyperKit?

27,743

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 root and hit enter, you will get a shell (no password), you will gett the shell:

enter image description here

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.

Share:
27,743

Related videos on Youtube

Jifeng Zhang
Author by

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, 2021

Comments

  • Jifeng Zhang
    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
    Gerry Gleason over 7 years
    This 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
    Jauco over 7 years
    for me it still works (feb-2017 1.13.0-beta39 using iterm2 terminal emulator)
  • Spencer Williams
    Spencer Williams about 7 years
    They 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 ran ls -l on that tty path, it turned out there was a link to it at /dev/ttys001, which is much easier to type.
  • Inanc Gumus
    Inanc Gumus about 7 years
    What can we do on this interface? I can't run node for example, I copied it somewhere else didn't work.
  • Inanc Gumus
    Inanc Gumus about 7 years
    Or does it enable me to connect to a network_mode=host container?
  • sapy
    sapy almost 7 years
    July 2017 - Works ... Mac OS Sierra . Docker Version 17.06.0-ce-mac19 (18663)
  • Mahdi
    Mahdi over 6 years
    Sep '17: Doesn't work for me (Sierra 10.12.6). The command just outputs whatever I write until I press Ctrl-Z
  • Jifeng Zhang
    Jifeng Zhang over 6 years
    @mahdix, if press enter, you will get a prompt. I have updated the instruction.
  • Mahdi
    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
    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
    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 use screen -ls.
  • seren
    seren over 5 years
    Thanks for the updated path. The accepted answer needs to be updated with this.
  • Rafael Eyng
    Rafael Eyng over 4 years
    What I don't understand: how come this VM doesn't have the command docker?
  • demisx
    demisx over 3 years
    Hmm... 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
    xenoterracide over 3 years
    this works for me, accessing the tty in catalina did not
  • lqbweb
    lqbweb over 3 years
  • smammy
    smammy over 3 years
    This 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
    smammy over 3 years
    This no longer works in Docker Desktop 3.
  • smammy
    smammy over 3 years
    This no longer works in Docker Desktop 3.
  • parity3
    parity3 about 3 years
    Somtimes 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.