Docker Desktop comes with scripts to enable completion for the
docker-compose commands. The completion scripts may be found inside
Docker.app, in the
Contents/Resources/etc/ directory and can be installed both in Bash and Zsh.
Bash has built-in support for completion To activate completion for Docker commands, these files need to be copied or symlinked to your
bash_completion.d/ directory. For example, if you installed bash via Homebrew:
etc=/Applications/Docker.app/Contents/Resources/etc ln -s $etc/docker.bash-completion $(brew --prefix)/etc/bash_completion.d/docker ln -s $etc/docker-compose.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-compose
Add the following to your
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
OR (this one worked for me!)
if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi
In my case since I’m using macOS Big Sur I wanted to change my default shell to bash. Big Sur comes with zsh as default. Below is my .bash_profile that worked for me. Yes, I used homebrew to install bash_completion. Not sure if this was necessary. Let me know what you think in the comments area below.
export PATH="/opt/homebrew/bin:$PATH" if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi