54

I have been using oh-my-zsh for a while now and the docker plugin as recently stopped working for me for some reason.

I checked my ~/.zshrc file and the plugin is included

plugins=(git colored-man colorize github jira vagrant virtualenv pip python brew osx zsh-syntax-highlighting docker)

I checked the ~/.oh-my-zsh/plugins/docker directory and there is a _docker file in there. Yet when I type docker and press Tab, I get none of the autocomplete shortcuts that I used to get.

I can confirm that my git plugin works just fine but not the docker plugin. Tried doing exec zsh and source ~/.zshrc and restarted my terminal but no luck.

Am I missing something?

Mikhail D'Souza
  • 583
  • 1
  • 4
  • 9
  • In my case I was looking for docker-compose functions, I forgot that docker has separate plugins: docker, docker-compose, docker-machine.. Maybe it's not the case, but it may help somebody else – funder7 Dec 15 '20 at 00:19

8 Answers8

252

You might want to try and remove any .zcompdump-(...) files you may have on your user's home directory - using something like rm ~/.zcompdump* on a terminal, or some file browser - and then reload the .zschrc file with the command source ~/.zshrc or restart the terminal - whichever works best for you. See this

Then see if it works.

Rui Carvalho
  • 3,376
  • 1
  • 21
  • 18
  • 8
    This worked for me too on Ubuntu Mate 18.04, zsh 5.4.2, mate-terminal 1.20.0. Had to delete `.zcompdump--5.4.2` and restart the terminal. – Cirquit Apr 24 '19 at 14:19
  • 7
    Worked for me on Mac OS Catalina – Leonardo Emilio Dominguez Oct 16 '19 at 02:18
  • 1
    Worked on Fedora ! Thank you for this simple answer. – Dinko Pehar Mar 07 '20 at 22:00
  • 1
    Had multiple .zcomp-dump* files in ~ and after deleting both docker autocomplete works perfectly. The solution has not generated any bugs on my system. Using OS X Catalina. – Richard Jarram Mar 25 '20 at 18:07
  • 1
    For those unaware, `source ~/.zshrc` also 'restarts' your terminal. No need to actually close your terminal, or lose what you're in the middle of. – MagicLegend May 01 '20 at 08:03
  • 1
    It works! But why? What is broken and how did that happen? – Cornelius Roemer May 15 '20 at 13:50
  • 2
    [1/2] @CorneliusRoemer The reason it works is because of how OMZ/ZSH plugins and autocomplete work. OMZ/ZSH uses .zcompdump as cache files for its shell completion system when you're typing, to make completion faster. These zcompdump files are compiled by OMZ/ZSH to map commands to functions it will run, many defined in plugins as well. So it runs through plugins folder and builds this cached file it uses while you type. When active plugin list changes in OMZ/ZSH config it does not automatically do what it should to rebuild this zcompdump cache file. By removing it you force it to be rebuilt. – Rui Carvalho Sep 20 '20 at 16:04
  • 1
    [2/2] It's actually safe to delete them, since they will be recreated if not there, in your user home folder. Also, OMZ/ZSH uses the hostname as the suffix to each .zcompdump file. You can also browse through OMZ code at https://github.com/ohmyzsh/ohmyzsh to understand how the plugin system works. Look at this file https://github.com/ohmyzsh/ohmyzsh/blob/master/oh-my-zsh.sh#L57-L71 and lines ~57 onwards to understand the usage of zcompdump files. – Rui Carvalho Sep 20 '20 at 16:04
65

It seems oh-my-zsh is not loading plugins/docker/_docker file. You must add it to ~/.zshrc in an another way. Add these lines to your ~/.zshrc file:

fpath+=($ZSH/plugins/docker)
autoload -U compinit && compinit
youhans
  • 6,101
  • 4
  • 27
  • 39
6

For me it was simply the case that I needed to launch Docker for the first time from spotlight on my Mac in order for Docker for Desktop to get the access it needed. Then the docker version command worked just fine.

Scott Skiles
  • 3,647
  • 6
  • 40
  • 64
3

Follow these steps if you are using oh-my-zsh and autocomplete is not working:

  1. Make the following three links:

    ln -s /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion /usr/local/share/zsh/site-functions/_docker
    ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.zsh-completion /usr/local/share/zsh/site-functions/_docker-machine
    ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.zsh-completion /usr/local/share/zsh/site-functions/_docker-compose
    
  2. Either add autoload -Uz compinit; compinit to .zshrc or run in your shell:

    echo "autoload -Uz compinit; compinit" >> .zshrc
    
double-beep
  • 5,031
  • 17
  • 33
  • 41
Anuj
  • 6,987
  • 3
  • 22
  • 25
3

In my case: Windows 10 + WSL2 + Hyper

I was having this error because I stopped Docker on Windows... Starting it again makes the error disappear in Hyper (thus, also in ZSH).

No .zshrc changes or additional commands to add inside.

Maxime Lafarie
  • 2,172
  • 1
  • 22
  • 41
  • Can you explain to me what your `Windows 10 + WSL2 + Hyper` looks like? A link to some docs online would be really helpful. – kapad Nov 09 '20 at 17:03
  • Sure, here are some links (sorry I can't find the original one I used before): https://blog.usejournal.com/how-i-turned-my-windows-pc-into-a-productivity-machine-for-development-wsl-hyper-oh-my-zsh-79ee614afbd2 // https://medium.com/@myrlandnu/guide-to-install-and-configure-hyper-for-windows-10-52a829c97b25 – Maxime Lafarie Nov 10 '20 at 08:27
1

@youhans's solution worked for me permanently. You might have permission issue to make needed adjustment on "zshrc". I have changed the permission to "read and write" and added the code snippet from @youhans's response to the end of "zshrc" file. Now completion system always works.

  • Before I had to type below snippet in command line whenever open a new terminal.

    autoload -Uz compinit && compinit

rcep
  • 13
  • 4
0

In my case it occurred because of an alias. I had defined alias docker=docker.exe. Removing that did it work again.

System & Environment

  • O.S.: Windows 10 Home, x64
  • Shell: Zsh (on Gitbash)
Leo Tapia
  • 131
  • 6
-36

I think you may be missing ,'s in between each plugin.

plugins=(git, colored-man, colorize, github, jira, vagrant, virtualenv, pip, python, brew, osx, zsh-syntax-highlighting, docker)

Alternatively you can place each plugin on a separate line:

plugins=(
  git
  colored-man
  colorize 
  github
  jira
  vagrant
  virtualenv
  pip
  python
  brew
  osx
  zsh-syntax-highlighting 
  docker
)
Behrang
  • 46,888
  • 25
  • 118
  • 160
Shmeinstein
  • 1
  • 1
  • 2