We will run through the instructions here and show a couple of examples of what it looks like when configured.nginx
Set up Bash competition through brewdocker
$ brew install bash-completion $ brew tap homebrew/completions
Update your .bashrc or .bash_profilebash
This snippet will update your .bashrc file that is executed every time you open a terminal.app
If you don't have a
.bashrc
file already then you may want to usechmod +x
and to add an extra line at the top of the file#!/bin/bash
ide
cat >> ~/.bashrc <<EOL if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi EOL
Add Docker-specific completionsui
cd /usr/local/etc/bash_completion.d ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
Now you can profit from doing things like this:this
Figuring out commandsspa
$ 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.rest
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 99b9505c7c18e51b1154e7d95f0e034eac4c9264ff2196501208ffd35644c37c
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:
99b9505c7c18e51b1154e7d95f0e034eac4c9264ff2196501208ffd35644c37c
$ 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.
In Docker 1.12RC we get a native, built-in orchestration model called Swarm Mode. Check out my quick tutorials below: