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 -O ~/
$ wget$(docker-compose --version | awk 'NR==1{print $NF}')/contrib/completion/bash/docker-compose -O ~/
$ wget -O ~/

and add the following to the end of your ~/.bash_profile (or ~/.bash_rc if running Linux) :

. ~/
. ~/
. ~/

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


Reference: Bash completion for Docker from our SCG partner Anthony Dahanne at the Anthony Dahanne’s blog blog.

Anthony Dahanne

Anthony Dahanne is a Java software developer for 8 years, his favorite topics are Android, building tools, Continuous Integration and, of course, core Java development. Working for Terracotta, he currently implements the REST management interface for EhCache.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Umair Aslam
Umair Aslam
8 years ago

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

Back to top button