Skip to content

Docker插件

This plugin adds auto-completion and aliases for docker.

To use it add docker to the plugins array in your zshrc file.

zsh
plugins=(... docker)

A copy of the completion script from the docker/cli git repo: https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker

Settings

By default, the completion doesn't allow option-stacking, meaning if you try to complete docker run -it <TAB> it won't work, because you're stacking the -i and -t options.

You can enable it by adding the lines below to your zshrc file, but be aware of the side effects:

This enables Zsh to understand commands like docker run -it ubuntu. However, by enabling this, this also makes Zsh complete docker run -u<tab> with docker run -uapprox which is not valid. The users have to put the space or the equal sign themselves before trying to complete.

Therefore, this behavior is disabled by default. To enable it:

sh
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes

Use old-style completion

If the current completion does not work well for you, you can enable legacy completion instead with the following setting. See https://github.com/ohmyzsh/ohmyzsh/issues/11789 for more information.

zsh
zstyle ':omz:plugins:docker' legacy-completion yes

Aliases

AliasCommandDescription
dbldocker buildBuild an image from a Dockerfile
dcindocker container inspectDisplay detailed information on one or more containers
dclsdocker container lsList all the running docker containers
dclsadocker container ls -aList all running and stopped containers
dibdocker image buildBuild an image from a Dockerfile (same as docker build)
diidocker image inspectDisplay detailed information on one or more images
dilsdocker image lsList docker images
dipudocker image pushPush an image or repository to a remote registry
dirmdocker image rmRemove one or more images
ditdocker image tagAdd a name and tag to a particular image
dlodocker container logsFetch the logs of a docker container
dncdocker network createCreate a new network
dncndocker network connectConnect a container to a network
dndcndocker network disconnectDisconnect a container from a network
dnidocker network inspectReturn information about one or more networks
dnlsdocker network lsList all networks the engine daemon knows about, including those spanning multiple hosts
dnrmdocker network rmRemove one or more networks
dpodocker container portList port mappings or a specific mapping for the container
dpudocker pullPull an image or a repository from a registry
drdocker container runCreate a new container and start it using the specified command
dritdocker container run -itCreate a new container and start it in an interactive shell
drmdocker container rmRemove the specified container(s)
drm!docker container rm -fForce the removal of a running container (uses SIGKILL)
dstdocker container startStart one or more stopped containers
drsdocker container restartRestart one or more containers
dstadocker stop $(docker ps -q)Stop all running containers
dstpdocker container stopStop one or more running containers
dtopdocker topDisplay the running processes of a container
dvidocker volume inspectDisplay detailed information about one or more volumes
dvlsdocker volume lsList all the volumes known to docker
dvprunedocker volume pruneCleanup dangling volumes
dxcdocker container execRun a new command in a running container
dxcitdocker container exec -itRun a new command in a running container in an interactive shell