Skip to content

Instantly share code, notes, and snippets.

@milansimek
Last active June 29, 2023 18:54
Show Gist options
  • Select an option

  • Save milansimek/a982570e335a27ae430779a21ccd66fa to your computer and use it in GitHub Desktop.

Select an option

Save milansimek/a982570e335a27ae430779a21ccd66fa to your computer and use it in GitHub Desktop.
Docker quick bash shell in running container. Allows you to type 'dbash container_name' to directly enter bash in container
#!/bin/bash
#Place this file in the following folder:
#/usr/local/bin/
# now run `dbash container_name` to enter bash shell in container
# or `dbash [tab][tab]` to use the autocomplete functionality
docker exec -t -i $1 env TERM=xterm bash
#!/bin/bash
#Place this file in the following folder:
#/usr/share/bash-completion/completions/
#IMPORTANT: Filename = dbash
#you might have to run the following command once:
#source /usr/share/bash-completion/completions/dbash
_dbash()
{
local cur=${COMP_WORDS[COMP_CWORD]}
CONTAINERS=`docker ps --format '{{.Names}}'`
COMPREPLY=( $(compgen -W "$CONTAINERS" -- $cur) )
}
dbash(){
docker exec -t -i $1 env TERM=xterm bash
}
complete -F _dbash dbash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment