-
-
Save developer-guy/942ac4dc361abfa6c94d57a02febac86 to your computer and use it in GitHub Desktop.
Getting a Shell in the Docker for Mac Moby VM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 2018 Update: Easiest option is Justin's repo and image | |
| ==================== | |
| docker run -it --rm --privileged --pid=host justincormack/nsenter1 | |
| # more info: https://github.com/justincormack/nsenter1 | |
| # | |
| ## Option 1: use Screen (not easy like nsenter) | |
| # | |
| # Note this isn't a list of commands to run in order. The first one gets you in the VM (hit return twice | |
| # to see a prompt). Then other commands are for managing that connection. Not a great CLI expirence but gets | |
| # the job done. | |
| # connect to tty on Docker for Mac VM | |
| screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty | |
| # disconnect that session but leave it open in background | |
| Ctrl-a d | |
| # list that session that's still running in background | |
| screen -ls | |
| # reconnect to that session (don't open a new one, that won't work and 2nd tty will give you garbled screen) | |
| screen -r | |
| # kill this session (window) and exit | |
| Ctrl-a k | |
| ## Option 2 (easier): Use nsenter in priviledged container | |
| # other option to connect w/o screen | |
| docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh | |
| # Phil Estes (Docker Maintainer) says this does: | |
| # it’s running a container (using the debian image..nothing special about it other than it apparently has | |
| # `nsenter` installed), with pid=host (so you are in the process space of the mini VM running Docker4Mac), | |
| # and then nsenter says “whatever is pid 1, use that as context, and enter all the namespaces of that, and run a shell there" | |
| # --or-- | |
| # from Justin Cormack (Docker Maintainer) | |
| # Personally I mostly use screen, but then I also use | |
| docker run -it --rm --privileged --pid=host justincormack/nsenter1 | |
| # too. That's my minimal nsenter image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment