Skip to content

Instantly share code, notes, and snippets.

@cqsd
Created September 9, 2021 18:42
Show Gist options
  • Save cqsd/3d59e937b74ba270b8c4c39e5b1e4307 to your computer and use it in GitHub Desktop.
Save cqsd/3d59e937b74ba270b8c4c39e5b1e4307 to your computer and use it in GitHub Desktop.
run a shell in the docker host (use on dOckeR for mac or windoze)
#!/bin/sh
# (in kubernetes, you'd use AllowPrivilegeEscalation probably, idk. exercise for the reader)
docker run -it \
--privileged \
--pid=host \
alpine \
nsenter -t 1 -m -u -n -i bash
# nsenter # exec something in a namespace (analogous to su -c)
# -t 1 # take contexts from pid 1 (ie when we enter namespaces later, we are using the ones seen by pid 1)
# -m # enter the pid 1 mount ns
# -u # enter the pid 1 uts ns
# -n # enter the pid 1 net ns
# -i # enter the pid 1 ipc ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment