17

I am trying to get Docker shell completion on this stack (OSX iTerm2 oh-my-zsh)

I followed this guide -> https://docs.docker.com/compose/completion/

First I executed this

$ mkdir -p ~/.zsh/completion
$ curl -L https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-compose

Then I added this two lines almost at the end ~/.zshrc file

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

Then in the terminal I run

source ~/.zshrc
exec $SHELL -l

But when I press tab it suggest the files and folders on the path

agusgambina
  • 6,229
  • 14
  • 54
  • 94

3 Answers3

41

You set up the completion for docker-compose not for docker. If you would like add the docker completion too then run the following command and reload your shell.

curl -L https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/zsh/_docker > ~/.zsh/completion/_docker 

Other solution (UPDATE):

Add the docker plugin to the .zshrc's plugin list:

  1. Open ~/.zshrc
  2. Add docker to the plugins list like this: plugins=(docker ...)
mgyongyosi
  • 2,557
  • 2
  • 13
  • 20
  • 1
    I got mine to work fine using the guide linked https://docs.docker.com/compose/completion/#zsh and making sure `plugins=(docker,git ...)` and reloaded the shell and it works great using tab completion successfully. – james-see Dec 16 '17 at 17:58
  • 2
    It works but doesnt list the containers if you try to run docker exec -it – Barbaros Alp May 16 '18 at 11:32
  • 7
    I tried everything and my Docker autocomplete wouldn't work on iterm2. This answer solved it for me, I hope it helps someone: https://stackoverflow.com/a/45406609/2056484 – Lucas Bustamante Mar 23 '19 at 23:28
  • 1
    @LucasBustamante It did help me! thank you! I notice that `compinit` should be at the end of config. – zx1986 Apr 10 '19 at 15:13
  • In MacOS Mojave adding `docker` into plugin list worked only after removing `.zcompdump*' files from the home directory (as suggested in this answer https://stackoverflow.com/a/55341741/1220546) – Timo Saloranta Apr 24 '19 at 09:07
  • in my case i only added plugin docker after following on docker doc with my /opt/homebrew/autocompletions/_docker directly sylmink without ln into usr/local/share/zsh, thankyou ... – Yogi Arif Widodo Feb 10 '22 at 12:59
11

Make sure you have the lastest version of oh-my-zsh by running: upgrade_oh_my_zsh

Also, it can't hurt to run rm ~/.zcompdump* after trying all the other answers.

Fixed it for me.

blkpingu
  • 1,556
  • 1
  • 18
  • 41
0
  1. Run vim ~/.zshrc on your iTerm2
  2. Find the line that contains plugins=() which normally will have git for example plugins=(git)
  3. make a change by pressing I at that line ( i for Insert Mode)
  4. change to plugins=(docker git) to add the docker extension and place ESC to exit insert mode
  5. save by type :w to save and exit by type :x
  6. restart your iTerm2 then docker completion should work now