Home » Shell Scripting » BASH » Bash completion for Docker

About 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.

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

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

Do you want to know how to develop your skillset to become a sysadmin Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. Introduction to NGINX

2. Apache HTTP Server Cookbook

3. VirtualBox Essentials

4. Nagios Monitoring Cookbook

5. Linux BASH Programming Cookbook

6. Postgresql Database Tutorial

 

and many more ....

 

I have read and agree to the terms & conditions

 

Subscribe
Notify of
guest

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

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Umair Aslam
Umair Aslam
6 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
fi