BASH
Bash completion for Docker
When you interact a lot with command line tools, such as : docker , docker-machine and docker-compose, command line completion (using the tab key) is a must.
Let’s have a look at how to enable bash completion for those docker command line tools
Mac user ? install bash-completion
I suppose you already use brew on Mac to install additional packages; it’s time to install bash-completion :
$ brew install bash-completion
Bash completion for docker, docker-machine and docker-compose
Run those 3 commands :
$ wget https://raw.githubusercontent.com/docker/docker/master/contrib/completion/bash/docker -O ~/.docker-completion.sh
$ wget https://raw.githubusercontent.com/docker/compose/$(docker-compose --version | awk 'NR==1{print $NF}')/contrib/completion/bash/docker-compose -O ~/.docker-compose-completion.sh
$ wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine.bash -O ~/.docker-machine-completion.sh
and add the following to the end of your ~/.bash_profile (or ~/.bash_rc if running Linux) :
. ~/.docker-completion.sh . ~/.docker-machine-completion.sh . ~/.docker-compose-completion.sh
Now source (if running Linux, source ~/.bash_rc)
$ source ~/.bash_profile
And enjoy tab’ing :
$ docker attach commit create diff exec help images info kill login logs pause ps push restart rmi save start stop top version wait build cp daemon events export history import inspect load logout network port pull rename rm run search stats tag unpause volume
$ docker-compose build kill migrate-to-labels port pull rm scale stop up help logs pause ps restart run start unpause version
$ docker-machine active create help ip ls restart scp start stop url config env inspect kill regenerate-certs rm ssh status upgrade
Resources
- docker-compose completion article on docker.com
- docker-machine completion scripts on github
- docker completion scripts on github
Reference: | Bash completion for Docker from our SCG partner Anthony Dahanne at the Anthony Dahanne’s blog blog. |
I ran into the following issue when tabbing for anything that includes colon : for instance images
-bash: __ltrim_colon_completions: command not found
Solved by adding the following in the ~/.bash_profile
if [ -f $(brew –prefix)/etc/bash_completion ]; then
. $(brew –prefix)/etc/bash_completion
fi