Docker: Installing bash completion

We will run through the instructions here and show a couple of examples of what it looks like when configured.

  • Set up Bash competition through brew

$ brew install bash-completion
$ brew tap homebrew/completions
  • Update your .bashrc or .bash_profile

This snippet will update your .bashrc file that is executed every time you open a terminal.

If you don't have a .bashrc file already then you may want to use chmod +x and to add an extra line at the top of the file #!/bin/bash

cat >> ~/.bashrc <<EOL
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
  • Add Docker-specific completions

cd /usr/local/etc/bash_completion.d
ln -s /Applications/
ln -s /Applications/
ln -s /Applications/


Now you can profit from doing things like this:

  • Figuring out commands

$ docker [tab]
attach   events   info     network  rename   service  unpause
build    exec     inspect  node     restart  start    update
commit   export   kill     pause    rm       stats    version
cp       help     load     port     rmi      stop     volume
create   history  login    ps       run      swarm    wait
daemon   images   logout   pull     save     tag      
diff     import   logs     push     search   top

Having done this myself I saw docker top - something brand new for me.

Display the running processes of a container

  • Auto-completing container names

Here I run an nginx container and then forget to give it a name.

$ docker run -d -P nginx

Commands like docker inspect or docker kill take an ID or name as an input, so if you're new to Docker you would probably copy/paste the whole container ID. Fortunately these commands also work with a few unique characters like below:


$ docker inspect 99b9
$ docker inspect fd3564

For when you want to be explicit about naming then tab-completion helps you out and will attempt to finish off the name or ID you started typing in.

Here I type just the first letter and hit tab. This even works with some of the crazy automatically generated container names that Docker can create.

$ docker inspect 9[tab]
$ docker inspect 99b9505c7c18e51b1154e7d95f0e034eac4c9264ff2196501208ffd35644c37c

Using names:

$ docker rm -f goof[tab]
$ docker rm -f goofy_curie

So I hope you found this useful - and I'm sure there are lots more ways you can take advantage of this. If you have more hints and hacks for completion let me know in the comments.

See also - swarm mode:

In Docker 1.12RC we get a native, built-in orchestration model called Swarm Mode. Check out my quick tutorials below:

Getting started with Swarm Mode