Master Docker Command Auto-Completion on macOS and Zsh: A Step-by-Step Guide
This article explains the recent Docker command restructuring, introduces the Management Command and sub‑command syntax, and provides detailed instructions for enabling powerful tab‑completion on macOS using Bash or Zsh, complete with code snippets and screenshots.
Introduction
Docker recently reorganized its command syntax: the old docker run style has become docker container run, separating commands into two groups—Management Commands (top‑level) and Commands (sub‑commands)—a change introduced in Docker 1.13.
docker run ...
# becomes
docker container run ...When you type docker and press Enter, Docker displays the two groups, making the overall command structure clearer.
The general syntax is:
docker <Management Command> <Sub‑Command <Opts/Args>>This means you only need to focus on the Management Command first; sub‑commands can be discovered as needed.
Docker Command Auto-Completion
Docker offers a comprehensive tab‑completion feature that lets the Tab key suggest commands and options automatically.
Install on macOS (Bash)
Run the following commands:
brew install bash-completion
sudo curl -L https://raw.githubusercontent.com/docker/compose/1.27.4/contrib/completion/bash/docker-compose -o /usr/local/etc/bash_completion.d/docker-composeEdit ~/.bash_profile and add:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fiReload the profile to apply changes:
source ~/.bash_profileInstall on Zsh
If you do not have Oh‑My‑Zsh, install it first, then execute:
mkdir -p ~/.zsh/completion
curl -L https://raw.githubusercontent.com/docker/compose/1.27.4/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-composeAdd the following to ~/.zshrc:
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit -iEnable the Docker plugins in the plugins list, for example: plugins=(... docker docker-compose) Reload Zsh to activate the completion:
source ~/.zshrcConclusion
With Docker’s auto‑completion, the Tab key can instantly suggest commands and options, making it faster than constantly consulting the documentation.
Reference: Docker Command Completion
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
