Skip to content

Instantly share code, notes, and snippets.

@nclv
Last active January 3, 2020 20:27
Show Gist options
  • Save nclv/84e3a1d082209d33a0dded750385d09c to your computer and use it in GitHub Desktop.
Save nclv/84e3a1d082209d33a0dded750385d09c to your computer and use it in GitHub Desktop.
alias dockershell="docker run --rm -i -t --entrypoint=/bin/bash"
alias dockershellsh="docker run --rm -i -t --entrypoint=/bin/sh"
function dockershellhere() {
dirname=${PWD##_/}
docker run --rm -it --entrypoint=/bin/bash -v `pwd`:/${dirname} -w /${dirname} "$@"
}
function dockershellshhere() {
dirname=${PWD##_/}
docker run --rm -it --entrypoint=/bin/sh -v `pwd`:/${dirname} -w /${dirname} "$@"
}
@nclv
Copy link
Author

nclv commented Jan 3, 2020

What do these do? They simply let me specify an image and drop into an interactive shell in a fresh, disposable environment. I can look around, make changes, test things, and then when I’m finished and type “exit”, everything is destroyed and cleaned up.

dockershell executes /bin/bash, while dockershellsh executes /bin/sh. This is useful since not every Docker image has bash installed.

The ones that end in here take it one step further and mount my current working directory inside the disposable container. This lets me interact with my files inside the disposable environment, and anything I write to that directory while inside the container persists after exit.

For example :

$ dockershell ubuntu:18.04

No spinning up a VM, no SSH, just instant shell access to test something out. And when I’m done it’s destroyed and the next time I run it I have a fresh instance again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment