Updated for Docker version 1.3

Removed insert command
Added create, pause, unpause and exec commands
Updated text througout commands description
This commit is contained in:
Bob Maerten 2014-10-20 16:16:42 +02:00
commit 000b1b2db8

View file

@ -3,7 +3,7 @@
# Docker autocompletion for oh-my-zsh # Docker autocompletion for oh-my-zsh
# Requires: Docker installed # Requires: Docker installed
# Author: Azaan (@aeonazaan) # Author: Azaan (@aeonazaan)
# Updates: Bob Maerten (@bobmaerten) for Docker v0.9+ # Updates: Bob Maerten (@bobmaerten) for Docker v0.9 & v1.3
# Paul van den Berg (@bergvandenp) for Docker v1.3+ # Paul van den Berg (@bergvandenp) for Docker v1.3+
@ -22,6 +22,15 @@ __docker_images() {
_describe 'images' img_cmd _describe 'images' img_cmd
} }
# output a selectable list of all docker commands
__docker_commands() {
declare -a cmd_list
NB=$(docker help 2>&1 | grep -n Commands | cut -f1 -d':')
NB=$((NB+1))
cmd_list=($(docker help 2>&1 | tail -n +${NB} | head -n -2 | awk 'NR>1{print $1}'))
_describe 'commands' cmd_list
}
# ----- Commands # ----- Commands
# Seperate function for each command, makes extension easier later # Seperate function for each command, makes extension easier later
# --------------------------- # ---------------------------
@ -34,8 +43,9 @@ __attach() {
__build() { __build() {
_arguments \ _arguments \
'--force-rm[Always remove intermediate containers, even after unsuccessful builds]' \
'--no-cache[Do not use cache when building the image]' \ '--no-cache[Do not use cache when building the image]' \
'(-q,--quiet)'{-q,--quiet}'[Suppress the verbose output generated by the containers]' \ '(-q,--quiet=)'{-q,--quiet=}'[Suppress the verbose output generated by the containers]' \
'--rm[Remove intermediate containers after a successful build]' \ '--rm[Remove intermediate containers after a successful build]' \
'(-t,--tag=)'{-t,--tag=}'[Repository name (and optionally a tag) to be applied to the resulting image in case of success]' \ '(-t,--tag=)'{-t,--tag=}'[Repository name (and optionally a tag) to be applied to the resulting image in case of success]' \
'*:files:_files' '*:files:_files'
@ -45,30 +55,78 @@ __commit() {
_arguments \ _arguments \
'(-a,--author=)'{-a,--author=}'[Author (eg. "John Hannibal Smith <hannibal@a-team.com>"]' \ '(-a,--author=)'{-a,--author=}'[Author (eg. "John Hannibal Smith <hannibal@a-team.com>"]' \
'(-m,--message=)'{-m,--message=}'[Commit message]' \ '(-m,--message=)'{-m,--message=}'[Commit message]' \
'--run=[Config automatically applied when the image is run.]' '(-p,--pause=)'{-p,--pause=}'[Pause container during commit]'
__docker_containers __docker_containers
} }
__cp() { __cp() {
__docker_containers __docker_containers
} }
__create() {
_arguments \
'(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR.]' \
'--add-host=[Add a custom host-to-IP mapping (host:ip)]' \
'(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \
'--cap-add=[Add Linux capabilities]' \
'--cap-drop=[Drop Linux capabilities]' \
'--cidfile=[Write the container ID to the file]' \
'--cpuset=[CPUs in which to allow execution (0-3, 0,1)]' \
'--device=[Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc)]' \
'--dns=[Set custom DNS servers]' \
'--dns-search=[Set custom DNS search domains]' \
'(-e,--env=)'{-e,--env=}'[Set environment variables]' \
'--entrypoint=[Overwrite the default ENTRYPOINT of the image]' \
'--env-file=[Read in a line delimited file of environment variables]' \
'--expose=[Expose a port from the container without publishing it to your host]' \
'(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \
'(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
'--link=[Add link to another container in the form of name:alias]' \
'--lxc-conf=[(lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"]' \
'(-m,--memory=)'{-m,--memory=}'[Memory limit (format: <number><optional unit>, where unit = b, k, m or g)]' \
'--name=[Assign a name to the container]' \
'--net=[Set the Network mode for the container]' \
'(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \
'(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host]' \
'--privileged=[Give extended privileges to this container]' \
'--restart=[Restart policy to apply when a container exits]' \
'--security-opt=[Security Options]' \
'(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-TTY]' \
'(-u,--user=)'{-u,--user=}'[Username or UID]' \
'(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)]' \
'--volumes-from=[Mount volumes from the specified container(s)]' \
'(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]'
__docker_images
}
__diff() { __diff() {
__docker_containers __docker_containers
} }
__events() { __events() {
_arguments \ _arguments \
'--since=[Show previously created events and then stream.]' '--since=[Show previously created events and then stream.]' \
'--until=[Stream events until this timestamp]'
}
__exec() {
_arguments \
'(-d,--detach=)'{-d,--detach=}'[Detached mode: run command in the background]' \
'(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
'(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-TTY]'
__docker_containers
} }
__export() { __export() {
__docker_containers __docker_containers
} }
__help() {
__docker_commands
}
__history() { __history() {
_arguments \ _arguments \
'--no-trunc=[Don''t truncate output]' \ '--no-trunc[Don''t truncate output]' \
'(-q,--quiet)'{-q,--quiet}'[Only show numeric IDs]' '(-q,--quiet)'{-q,--quiet}'[Only show numeric IDs]'
__docker_images __docker_images
} }
@ -78,8 +136,7 @@ __images() {
'(-a,--all)'{-a,--all}'[Show all images (by default filter out the intermediate images used to build)]' \ '(-a,--all)'{-a,--all}'[Show all images (by default filter out the intermediate images used to build)]' \
'--no-trunc[Don''t truncate output]' \ '--no-trunc[Don''t truncate output]' \
'(-q,--quiet=)'{-q,--quiet=}'[Only show numeric IDs]' \ '(-q,--quiet=)'{-q,--quiet=}'[Only show numeric IDs]' \
'(-t,--tree=)'{-t,--tree=}'[Output graph in tree format]' \ '(-t,--tree=)'{-t,--tree=}'[Output graph in tree format]'
'(-v,--viz=)'{-v,--viz=}'[Output graph in graphviz format]'
__docker_images __docker_images
} }
@ -91,22 +148,23 @@ __info() {
# no arguments # no arguments
} }
__insert() {
__docker_images
_arguments '*:files:_files'
}
__inspect() { __inspect() {
__docker_images __docker_images
_arguments \
'(-f,--format=)'{-f,--format=}'[Format the output using the given go template.]'
__docker_containers __docker_containers
} }
__kill() { __kill() {
_arguments \
'(-s,--signal=)'{-s,--signal=}'[Signal to send to the container]'
__docker_containers __docker_containers
} }
__load() { __load() {
_arguments '*:files:_files' _arguments \
'(-i,--input=)'{-i,--input=}'[Read from a tar archive file, instead of STDIN]' \
'*:files:_files'
} }
__login() { __login() {
@ -116,9 +174,15 @@ __login() {
'(-u,--username=)'{-u,-username=}'[Username]' '(-u,--username=)'{-u,-username=}'[Username]'
} }
__logout() {
# no autocomplete
}
__logs() { __logs() {
_arguments \ _arguments \
'(-f,--follow)'{-f,-follow}'[Follow log output]' '(-f,--follow=)'{-f,--follow=}'[Follow log output]' \
'(-t,--timestamps=)'{-t,--timestamps=}'[Show timestamps]' \
'--tail[Output the specified number of lines at the end of logs (defaults to all logs)]'
__docker_containers __docker_containers
} }
@ -130,21 +194,26 @@ __top() {
__docker_containers __docker_containers
} }
__pause() {
__docker_containers
}
__ps() { __ps() {
_arguments \ _arguments \
'(-a,--all)'{-a,--all}'[Show all containers. Only running containers are shown by default.]' \ '(-a,--all=)'{-a,--all=}'[Show all containers. Only running containers are shown by default.]' \
'--before-id=[Show only container created before Id, include non-running ones.]' \ '--before=[Show only container created before Id or Name, include non-running ones.]' \
'(-l,--latest)'{-l,--latest}'[Show only the latest created container, include non-running ones.]' \ '(-f,--filter=)'{-f,--filter=}'[Provide filter values.]' \
'-n=[Show n last created containers, include non-running ones. default=-1.]' \ '(-l,--latest=)'{-l,--latest=}'[Show only the latest created container, include non-running ones.]' \
'-n=[Show n last created containers, include non-running ones.]' \
'--no-trunc[Don''t truncate output]' \ '--no-trunc[Don''t truncate output]' \
'(-q,--quiet)'{-q,--quiet}'[Only display numeric IDs]' \ '(-q,--quiet=)'{-q,--quiet=}'[Only display numeric IDs]' \
'(-s,--size)'{-s,--size}'[Display sizes]' \ '(-s,--size=)'{-s,--size=}'[Display sizes]' \
'--since-id=[Show only containers created since Id, include non-running ones.]' '--since=[Show only containers created since Id or Name, include non-running ones.]'
} }
__pull() { __pull() {
_arguments \ _arguments \
'(-t,--tag=)'{-t,--tag=}'[Download tagged image in repository]' '(-a,--all-tags=)'{-a,--all-tags=}'[Download all tagged images in the repository]'
} }
__push() { __push() {
@ -153,7 +222,7 @@ __push() {
__restart() { __restart() {
_arguments \ _arguments \
'(-t,--time=)'{-t,--time=}'[Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default=10]' '(-t,--time=)'{-t,--time=}'[Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds.]'
__docker_containers __docker_containers
} }
@ -167,35 +236,45 @@ __rm() {
__rmi() { __rmi() {
_arguments \ _arguments \
'(-f,--force=)'{-f,--force=}'[Force]' '(-f,--force=)'{-f,--force=}'[Force removal of the image]' \
'--no-prune[Do not delete untagged parent]'
__docker_images __docker_images
} }
__run() { __run() {
_arguments \ _arguments \
'(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \ '(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR.]' \
'(-a,--attach=)'{-a,--attach=}'[Attach to stdin, stdout or stderr.]' \ '--add-host=[Add a custom host-to-IP mapping (host:ip)]' \
'(-c,--cpu-shares=)'{-c,--cpu-shares=}': CPU shares (relative weight)]' \ '(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \
'--cap-add=[Add Linux capabilities]' \
'--cap-drop=[Drop Linux capabilities]' \
'--cidfile=[Write the container ID to the file]' \ '--cidfile=[Write the container ID to the file]' \
'(-d,--detach=)'{-d,--detach=}'[Detached mode: Run container in the background, print new container id]' \ '--cpuset=[CPUs in which to allow execution (0-3, 0,1)]' \
'--dns=[Set custom dns servers]' \ '(-d,--detach=)'{-d,--detach=}'[Detached mode: run the container in the background and print the new container ID]' \
'--device=[Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc)]' \
'--dns=[Set custom DNS servers]' \
'--dns-search=[Set custom DNS search domains]' \
'(-e,--env=)'{-e,--env=}'[Set environment variables]' \ '(-e,--env=)'{-e,--env=}'[Set environment variables]' \
'--entrypoint=[Overwrite the default entrypoint of the image]' \ '--entrypoint=[Overwrite the default ENTRYPOINT of the image]' \
'--env-file=[Read in a line delimited file of environment variables]' \
'--expose=[Expose a port from the container without publishing it to your host]' \ '--expose=[Expose a port from the container without publishing it to your host]' \
'(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \ '(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \
'(-i,--interactive=)'{-i,--interactive=}'[Keep stdin open even if not attached]' \ '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \
'--link=[Add link to another container (name:alias)]' \ '--link=[Add link to another container in the form of name:alias]' \
'--lxc-conf=[Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"]' \ '--lxc-conf=[(lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"]' \
'(-m,--memory=)'{-m,--memory=}'[Memory limit (format: <number><optional unit>, where unit = b, k, m or g)]' \ '(-m,--memory=)'{-m,--memory=}'[Memory limit (format: <number><optional unit>, where unit = b, k, m or g)]' \
'(-n,--networking=)'{-n,--networking=}'[Enable networking for this container]' \
'--name=[Assign a name to the container]' \ '--name=[Assign a name to the container]' \
'(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host (format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort) (use "docker port" to see the actual mapping)]' \ '--net=[Set the Network mode for the container]' \
'(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \
'(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host]' \
'--privileged=[Give extended privileges to this container]' \ '--privileged=[Give extended privileges to this container]' \
'--restart=[Restart policy to apply when a container exits]' \
'--rm=[Automatically remove the container when it exits (incompatible with -d)]' \ '--rm=[Automatically remove the container when it exits (incompatible with -d)]' \
'--sig-proxy=[Proxify all received signal to the process (even in non-tty mode)]' \ '--security-opt=)'{--security-opt=}'[Security Options]' \
'(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-tty]' \ '--sig-proxy=[Proxy received signals to the process (even in non-TTY mode). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.]' \
'(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-TTY]' \
'(-u,--user=)'{-u,--user=}'[Username or UID]' \ '(-u,--user=)'{-u,--user=}'[Username or UID]' \
'(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)]' \ '(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)]' \
'--volumes-from=[Mount volumes from the specified container(s)]' \ '--volumes-from=[Mount volumes from the specified container(s)]' \
'(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]' '(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]'
__docker_images __docker_images
@ -203,19 +282,21 @@ __run() {
__search() { __search() {
_arguments \ _arguments \
'--no-trunc=[Don''t truncate output]' \ '--automated[Only show automated builds]' \
'-s,--stars=)'{-s,--stars=}'[Only displays with at least xxx stars]' \ '--no-trunc[Don''t truncate output]' \
'-t,--trusted=)'{-t,--trusted=}'[Only show trusted builds]' '(-s,--stars=)'{-s,--stars=}'[Only displays with at least x stars]'
} }
__save() { __save() {
_arguments \
'(-o,--output=)'{-o,--output=}'[Write to a file, instead of STDOUT]'
__docker_images __docker_images
} }
__start() { __start() {
_arguments \ _arguments \
'(-a,--attach=)'{-a,--attach=}'[Attach container''s stdout/stderr and forward all signals to the process]' \ '(-a,--attach=)'{-a,--attach=}'[Attach container''s STDOUT and STDERR and forward all signals to the process]' \
'(-i,--interactive=)'{-i,--interactive=}'[Attach container''s stdin]' '(-i,--interactive=)'{-i,--interactive=}'[Attach container''s STDIN]'
__docker_containers __docker_containers
} }
@ -225,7 +306,7 @@ __stats() {
__stop() { __stop() {
_arguments \ _arguments \
'(-t,--time=)'{-t,--time=}'[Number of seconds to wait for the container to stop before killing it.]' '(-t,--time=)'{-t,--time=}'[Number of seconds to wait for the container to stop before killing it. Default is 10 seconds.]'
__docker_containers __docker_containers
} }
@ -235,6 +316,10 @@ __tag() {
__docker_images __docker_images
} }
__unpause() {
__docker_containers
}
__version() { __version() {
# no arguments # no arguments
} }
@ -257,38 +342,43 @@ __exec() {
local -a _1st_arguments local -a _1st_arguments
_1st_arguments=( _1st_arguments=(
"attach":"Attach to a running container" "attach":"Attach to a running container"
"build":"Build a container from a Dockerfile" "build":"Build an image from a Dockerfile"
"commit":"Create a new image from a container's changes" "commit":"Create a new image from a container's changes"
"cp":"Copy files/folders from the containers filesystem to the host path" "cp":"Copy files/folders from a container's filesystem to the host path"
"create":"Create a new container"
"diff":"Inspect changes on a container's filesystem" "diff":"Inspect changes on a container's filesystem"
"events":"Get real time events from the server" "events":"Get real time events from the server"
"exec":"Run a command in an existing container"
"export":"Stream the contents of a container as a tar archive" "export":"Stream the contents of a container as a tar archive"
"help":"Display help for a given command"
"history":"Show the history of an image" "history":"Show the history of an image"
"images":"List images" "images":"List images"
"import":"Create a new filesystem image from the contents of a tarball" "import":"Create a new filesystem image from the contents of a tarball"
"info":"Display system-wide information" "info":"Display system-wide information"
"insert":"Insert a file in an image"
"inspect":"Return low-level information on a container" "inspect":"Return low-level information on a container"
"kill":"Kill a running container" "kill":"Kill a running container"
"load":"Load an image from a tar archive" "load":"Load an image from a tar archive"
"login":"Register or Login to the docker registry server" "login":"Register or log in to a Docker registry server"
"logout":"Log out from a Docker registry server"
"logs":"Fetch the logs of a container" "logs":"Fetch the logs of a container"
"port":"Lookup the public-facing port which is NAT-ed to PRIVATE_PORT" "port":"Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"
"pause":"Pause all processes within a container"
"ps":"List containers" "ps":"List containers"
"pull":"Pull an image or a repository from the docker registry server" "pull":"Pull an image or a repository from a Docker registry server"
"push":"Push an image or a repository to the docker registry server" "push":"Push an image or a repository to a Docker registry server"
"restart":"Restart a running container" "restart":"Restart a running container"
"rm":"Remove one or more containers" "rm":"Remove one or more containers"
"rmi":"Remove one or more images" "rmi":"Remove one or more images"
"run":"Run a command in a new container" "run":"Run a command in a new container"
"save":"Save an image to a tar archive" "save":"Save an image to a tar archive"
"search":"Search for an image in the docker index" "search":"Search for an image on the Docker Hub"
"start":"Start a stopped container" "start":"Start a stopped container"
"stats":"Display a live stream of one or more containers' resource usage statistics" "stats":"Display a live stream of one or more containers' resource usage statistics"
"stop":"Stop a running container" "stop":"Stop a running container"
"tag":"Tag an image into a repository" "tag":"Tag an image into a repository"
"top":"Lookup the running processes of a container" "top":"Lookup the running processes of a container"
"version":"Show the docker version information" "unpause":"Unpause a paused container"
"version":"Show the Docker version information"
"wait":"Block until a container stops, then print its exit code" "wait":"Block until a container stops, then print its exit code"
"exec":"Run a task inside a running container" "exec":"Run a task inside a running container"
) )
@ -308,14 +398,20 @@ case "$words[1]" in
__build ;; __build ;;
commit) commit)
__commit ;; __commit ;;
create)
__create ;;
cp) cp)
__cp ;; __cp ;;
diff) diff)
__diff ;; __diff ;;
events) events)
__events ;; __events ;;
exec)
__exec ;;
export) export)
__export ;; __export ;;
help)
__help ;;
history) history)
__history ;; __history ;;
images) images)
@ -324,8 +420,6 @@ case "$words[1]" in
__import ;; __import ;;
info) info)
__info ;; __info ;;
insert)
__insert ;;
inspect) inspect)
__inspect ;; __inspect ;;
kill) kill)
@ -334,8 +428,12 @@ case "$words[1]" in
__load ;; __load ;;
login) login)
__login ;; __login ;;
logout)
__logout ;;
logs) logs)
__logs ;; __logs ;;
pause)
__pause ;;
port) port)
__port ;; __port ;;
ps) ps)
@ -366,6 +464,8 @@ case "$words[1]" in
__tag ;; __tag ;;
top) top)
__top ;; __top ;;
unpause)
__unpause ;;
version) version)
__version ;; __version ;;
wait) wait)