Operations 5 min read

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.

Programmer DD
Programmer DD
Programmer DD
Master Docker Command Auto-Completion on macOS and Zsh: A Step-by-Step Guide

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-compose

Edit ~/.bash_profile and add:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

Reload the profile to apply changes:

source ~/.bash_profile

Install 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-compose

Add the following to ~/.zshrc:

fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit -i

Enable the Docker plugins in the plugins list, for example: plugins=(... docker docker-compose) Reload Zsh to activate the completion:

source ~/.zshrc

Conclusion

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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsBashauto-completionzsh
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.