Command-line completion
Estimated reading time: 3 minutes
Compose comes with command completion for the bash and zsh shell.
Install command completion
Bash
Make sure bash completion is installed.
Linux
- 
    On a current Linux OS (in a non-minimal installation), bash completion should be available. 
- 
    Place the completion script in /etc/bash_completion.d/.$ sudo curl \ -L https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-compose \ -o /etc/bash_completion.d/docker-compose
- 
    Reload your terminal. You can close and then open a new terminal, or reload your setting with source ~/.bashrccommand in your current terminal.
Mac
Install via Homebrew
- Install with brew install bash-completion.
- 
    After the installation, Brew displays the installation path. Make sure to place the completion script in the path. For example, place the completion script in /usr/local/etc/bash_completion.d/.$ sudo curl \ -L https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/bash/docker-compose \ -o /usr/local/etc/bash_completion.d/docker-compose
- 
    Add the following to your ~/.bash_profile:if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi
- You can source your ~/.bash_profileor launch a new terminal to utilize completion.
Install via MacPorts
- 
    Run sudo port install bash-completionto install bash completion.
- 
    Add the following lines to ~/.bash_profile:if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then . /opt/local/etc/profile.d/bash_completion.sh fi
- 
    You can source your ~/.bash_profileor launch a new terminal to utilize completion.
Zsh
Make sure you have installed oh-my-zsh on your computer.
With oh-my-zsh shell
Add docker and docker-compose to the plugins list in ~/.zshrc to run
autocompletion within the oh-my-zsh shell. In the following example, ...
represent other Zsh plugins you may have installed. After that, type source ~/.zshrc to bring the changes. 
To test whether it is successful, type docker ps and then press the Tab key.
plugins=(... docker docker-compose)
Without oh-my-zsh shell
- 
    Place the completion script in your /path/to/zsh/completion(typically~/.zsh/completion/):$ mkdir -p ~/.zsh/completion $ curl \ -L https://raw.githubusercontent.com/docker/compose/v2.5.0/contrib/completion/zsh/_docker-compose \ -o ~/.zsh/completion/_docker-compose
- 
    Include the directory in your $fpathby adding in~/.zshrc:fpath=(~/.zsh/completion $fpath)
- 
    Make sure compinitis loaded or do it by adding in~/.zshrc:autoload -Uz compinit && compinit -i
- 
    Then reload your shell: $ exec $SHELL -l
Available completions
Depending on what you typed on the command line so far, it completes:
- available docker-compose commands
- options that are available for a particular command
- service names that make sense in a given context, such as services with running or stopped instances or services based on images vs. services based on Dockerfiles. For docker-compose scale, completed service names automatically have “=” appended.
- arguments for selected options. For example, docker-compose kill -scompletes some signals like SIGHUP and SIGUSR1.
Enjoy working with Compose faster and with fewer typos!
Compose documentation
- User guide
- Installing Compose
- Command line reference
- Compose file reference
- Sample apps with Compose