Aliasing docker exec -it some_container_name bash
to d some_container_name
.
Step 1.1 Add to your .bashrc
d(){
docker exec -it $1 bash
}
Step 1.2 Then source it
source ~/.bashrc
Step 2.1 For autocompletion, create /etc/bash_completion.d/d
and copy to the following
_d()
{
_script_commands=$(docker ps | sed '1d' | awk '{print $NF}')
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${_script_commands}" -- ${cur}) )
return 0
}
complete -o nospace -F _d d
Step 2.2 Source it
source /etc/bash_completion.d/d
Step 3 🎉, Bash into containers using the alias, and complete the container with tab.
d some_container_name