cli: zsh autocompletion is broken

Steps to reproduce the issue:

  1. add docker to the plugins array
  2. type docker and hit tab twice

Describe the results you received: list of the files in the current directory

Describe the results you expected: docker commands such as run

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 2
Server Version: 17.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.27-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952 GiB
Name: moby
ID: G4R3:BP7S:FOLV:44UL:RWQ7:Z4FP:PPAC:VGD5:GDJR:LQPP:VTEC:B2QR
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 16
 Goroutines: 26
 System Time: 2017-06-28T18:09:21.525357926Z
 EventsListeners: 1
No Proxy: *.local, 169.254/16
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

host os:osx sierra 10.12.16 beta

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 33 (5 by maintainers)

Most upvoted comments

Although @leite’s solution worked for me too, manually removing the shell’s completion database via

rm -v ~/.zcompdump*

forces the shell to rebuild it and the completion for Docker finally starts working, without adding

autoload -Uz compinit && compinit

to my .zshrc file.

I solved the issue <del>removing docker-ce and installing docker & docker.io from ubuntu repository</del>

<del>and also</del> put these two lines at the end of my .zshrc

autoload -Uz compinit
compinit

thanks @naoliv

rm ~/.zcompdump*

Work for me.

Sorry I misread the content of your screenshot. I assume that your tree looks like that ~/.oh-my-zsh/plugins/docker/_docker.

I think the array in your ~/.zshrc should be plugins=(git docker) (space separated) instead of plugins=(git,docker)

The solution from @leite worked for me as well. Can anyone explain why this works? Why it’s necessary that I add this and why it isn’t in the core already?

If you’ve tried all of the above, and it zsh-completion for docker still doesn’t work for you, that may be because you’re in my situation:

  • using oh-my-zshell
  • file ~/.oh-my-zshell/plugins/docker/_docker is not loaded I don’t know why this file is in the standard plugins folder, but I’ve head to add it to the zsh-completions fpath variable explicitly per the mentioned stackoverflow answer:
  plugins=(git)

  # Docker completions don't follow the standard, and path needs to be added directly to zsh-completions
  # Also, "rm ~/.zcompdump*", and "source ~/.zshrc"
  # https://stackoverflow.com/questions/37428133/zsh-docker-plugin-not-working
  fpath+=($ZSH/plugins/docker)

  plugins=(zsh-completions)
  autoload -U compinit && compinit

TL;DR https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org

rm ~/.zcompdump* and reopening terminal worked for me too (macOS Catalina 10.15.1). No need to do compinit as mentioned above - which also works btw.

@jphuynh … like charm, thank you! I had to logout/ login. The autocomplete for the images also works now!

@jphuynh yep that was the issue 🥇 thank you so much when i replace commas with spaces it worked like a charm .

hi this is the line of plugins

plugins=(git,docker)

And this is what I read on the internet to prevent username on the prompt


prompt_context(){}

I don’t know if it has something to do with this.

And these are the plugins containing the word docker

Clean install Ubuntu 22.04 and the issue still there.

I added these lines at the end of the .zshrc without success :

autoload -Uz compinit
compinit

I’m stilling unable to use the autocompletion for docker (docker-compose is working):

plugins=(git docker-compose docker)
source $ZSH/oh-my-zsh.sh

Any idea what am I supposed to do ?

Tkx

For those struggling with this problem in 2022: if you’re using Oh My Zsh and Antigen, just ensure you’re executing source $ZSH/oh-my-zsh.sh AFTER defining plugins=(docker docker-compose).

For some reason I did not have this script loaded and it wasn’t working, after adding it, autocomplete works (my ~/.zshrc is really old and was migrated between several computers with different OSes, so maybe I did something wrong at some point). With this script loaded it’s not required to override fpath.