docker 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972
  1. #!/bin/bash
  2. #
  3. # bash completion file for core docker commands
  4. #
  5. # This script provides completion of:
  6. # - commands and their options
  7. # - container ids and names
  8. # - image repos and tags
  9. # - filepaths
  10. #
  11. # To enable the completions either:
  12. # - place this file in /etc/bash_completion.d
  13. # or
  14. # - copy this file to e.g. ~/.docker-completion.sh and add the line
  15. # below to your .bashrc after bash completion features are loaded
  16. # . ~/.docker-completion.sh
  17. #
  18. # Configuration:
  19. #
  20. # For several commands, the amount of completions can be configured by
  21. # setting environment variables.
  22. #
  23. # DOCKER_COMPLETION_SHOW_NETWORK_IDS
  24. # DOCKER_COMPLETION_SHOW_NODE_IDS
  25. # DOCKER_COMPLETION_SHOW_SERVICE_IDS
  26. # "no" - Show names only (default)
  27. # "yes" - Show names and ids
  28. #
  29. # You can tailor completion for the "events", "history", "inspect", "run",
  30. # "rmi" and "save" commands by settings the following environment
  31. # variables:
  32. #
  33. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  34. # "none" - Show names only (default)
  35. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  36. # "all" - Show names and ids, including intermediate image IDs
  37. #
  38. # DOCKER_COMPLETION_SHOW_TAGS
  39. # "yes" - include tags in completion options (default)
  40. # "no" - don't include tags in completion options
  41. #
  42. # Note:
  43. # Currently, the completions will not work if the docker daemon is not
  44. # bound to the default communication port/socket
  45. # If the docker daemon is using a unix socket for communication your user
  46. # must have access to the socket for the completions to function correctly
  47. #
  48. # Note for developers:
  49. # Please arrange options sorted alphabetically by long name with the short
  50. # options immediately following their corresponding long form.
  51. # This order should be applied to lists, alternatives and code blocks.
  52. __docker_previous_extglob_setting=$(shopt -p extglob)
  53. shopt -s extglob
  54. __docker_q() {
  55. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  56. }
  57. __docker_complete_containers_all() {
  58. local IFS=$'\n'
  59. local containers=( $(__docker_q ps -aq --no-trunc) )
  60. if [ "$1" ]; then
  61. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  62. fi
  63. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  64. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  65. unset IFS
  66. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  67. }
  68. __docker_complete_containers_running() {
  69. __docker_complete_containers_all '.State.Running'
  70. }
  71. __docker_complete_containers_stopped() {
  72. __docker_complete_containers_all 'not .State.Running'
  73. }
  74. __docker_complete_containers_pauseable() {
  75. __docker_complete_containers_all 'and .State.Running (not .State.Paused)'
  76. }
  77. __docker_complete_containers_unpauseable() {
  78. __docker_complete_containers_all '.State.Paused'
  79. }
  80. __docker_complete_container_names() {
  81. local containers=( $(__docker_q ps -aq --no-trunc) )
  82. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  83. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  84. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  85. }
  86. __docker_complete_container_ids() {
  87. local containers=( $(__docker_q ps -aq) )
  88. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  89. }
  90. __docker_complete_images() {
  91. local images_args=""
  92. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  93. all)
  94. images_args="--no-trunc -a"
  95. ;;
  96. non-intermediate)
  97. images_args="--no-trunc"
  98. ;;
  99. esac
  100. local repo_print_command
  101. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  102. repo_print_command='print $1; print $1":"$2'
  103. else
  104. repo_print_command='print $1'
  105. fi
  106. local awk_script
  107. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  108. all|non-intermediate)
  109. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  110. ;;
  111. none|*)
  112. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  113. ;;
  114. esac
  115. local images=$(__docker_q images $images_args | awk "$awk_script")
  116. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  117. __ltrim_colon_completions "$cur"
  118. }
  119. __docker_complete_image_repos() {
  120. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  121. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  122. }
  123. __docker_complete_image_repos_and_tags() {
  124. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  125. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  126. __ltrim_colon_completions "$cur"
  127. }
  128. __docker_complete_containers_and_images() {
  129. __docker_complete_containers_all
  130. local containers=( "${COMPREPLY[@]}" )
  131. __docker_complete_images
  132. COMPREPLY+=( "${containers[@]}" )
  133. }
  134. # Returns the names and optionally IDs of networks.
  135. # The selection can be narrowed by an optional filter parameter, e.g. 'type=custom'
  136. __docker_networks() {
  137. local filter="$1"
  138. # By default, only network names are completed.
  139. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
  140. local fields='$2'
  141. [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
  142. __docker_q network ls --no-trunc ${filter:+-f "$filter"} | awk "NR>1 {print $fields}"
  143. #__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
  144. }
  145. __docker_complete_networks() {
  146. COMPREPLY=( $(compgen -W "$(__docker_networks $@)" -- "$cur") )
  147. }
  148. __docker_complete_network_ids() {
  149. COMPREPLY=( $(compgen -W "$(__docker_q network ls -q --no-trunc)" -- "$cur") )
  150. }
  151. __docker_complete_network_names() {
  152. COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") )
  153. }
  154. __docker_complete_containers_in_network() {
  155. local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1")
  156. COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
  157. }
  158. __docker_complete_volumes() {
  159. COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
  160. }
  161. __docker_plugins() {
  162. __docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $1: //p"
  163. }
  164. __docker_complete_plugins() {
  165. COMPREPLY=( $(compgen -W "$(__docker_plugins $1)" -- "$cur") )
  166. }
  167. __docker_runtimes() {
  168. __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p'
  169. }
  170. __docker_complete_runtimes() {
  171. COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
  172. }
  173. # Returns a list of all nodes. Additional arguments to `docker node`
  174. # may be specified in order to filter the node list, e.g.
  175. # `__docker_nodes --filter role=manager`
  176. # By default, only node names are completed.
  177. # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs.
  178. # An optional first argument `--id|--name` may be used to limit
  179. # the output to the IDs or names of matching nodes. This setting takes
  180. # precedence over the environment setting.
  181. __docker_nodes() {
  182. local fields='$2' # default: node name only
  183. [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name
  184. if [ "$1" = "--id" ] ; then
  185. fields='$1' # IDs only
  186. shift
  187. elif [ "$1" = "--name" ] ; then
  188. fields='$2' # names only
  189. shift
  190. fi
  191. __docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}"
  192. }
  193. # Applies completion of nodes based on the current value of `$cur` or
  194. # the value of the optional first argument `--cur`, if given.
  195. # Additional filters may be appended, see `__docker_nodes`.
  196. __docker_complete_nodes() {
  197. local current=$cur
  198. if [ "$1" = "--cur" ] ; then
  199. current="$2"
  200. shift 2
  201. fi
  202. COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") )
  203. }
  204. __docker_complete_nodes_plus_self() {
  205. __docker_complete_nodes "$@"
  206. COMPREPLY+=( self )
  207. }
  208. # Returns a list of all services. Additional arguments to `docker service ls`
  209. # may be specified in order to filter the service list, e.g.
  210. # `__docker_services --filter name=xxx`
  211. # By default, only node names are completed.
  212. # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete service IDs.
  213. # An optional first argument `--id|--name` may be used to limit
  214. # the output to the IDs or names of matching services. This setting takes
  215. # precedence over the environment setting.
  216. __docker_services() {
  217. local fields='$2' # default: service name only
  218. [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
  219. if [ "$1" = "--id" ] ; then
  220. fields='$1' # IDs only
  221. shift
  222. elif [ "$1" = "--name" ] ; then
  223. fields='$2' # names only
  224. shift
  225. fi
  226. __docker_q service ls "$@" | awk "NR>1 {print $fields}"
  227. }
  228. # Applies completion of services based on the current value of `$cur` or
  229. # the value of the optional first argument `--cur`, if given.
  230. # Additional filters may be appended, see `__docker_services`.
  231. __docker_complete_services() {
  232. local current=$cur
  233. if [ "$1" = "--cur" ] ; then
  234. current="$2"
  235. shift 2
  236. fi
  237. COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
  238. }
  239. # Appends the word passed as an argument to every word in `$COMPREPLY`.
  240. # Normally you do this with `compgen -S`. This function exists so that you can use
  241. # the __docker_complete_XXX functions in cases where you need a suffix.
  242. __docker_append_to_completions() {
  243. COMPREPLY=( ${COMPREPLY[@]/%/"$1"} )
  244. }
  245. # Finds the position of the first word that is neither option nor an option's argument.
  246. # If there are options that require arguments, you should pass a glob describing those
  247. # options, e.g. "--option1|-o|--option2"
  248. # Use this function to restrict completions to exact positions after the argument list.
  249. __docker_pos_first_nonflag() {
  250. local argument_flags=$1
  251. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  252. while [ $counter -le $cword ]; do
  253. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  254. (( counter++ ))
  255. # eat "=" in case of --option=arg syntax
  256. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  257. else
  258. case "${words[$counter]}" in
  259. -*)
  260. ;;
  261. *)
  262. break
  263. ;;
  264. esac
  265. fi
  266. # Bash splits words at "=", retaining "=" as a word, examples:
  267. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  268. while [ "${words[$counter + 1]}" = "=" ] ; do
  269. counter=$(( counter + 2))
  270. done
  271. (( counter++ ))
  272. done
  273. echo $counter
  274. }
  275. # If we are currently completing the value of a map option (key=value)
  276. # which matches the extglob given as an argument, returns key.
  277. # This function is needed for key-specific completions.
  278. __docker_map_key_of_current_option() {
  279. local glob="$1"
  280. local key glob_pos
  281. if [ "$cur" = "=" ] ; then # key= case
  282. key="$prev"
  283. glob_pos=$((cword - 2))
  284. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  285. key=${cur%=*}
  286. glob_pos=$((cword - 1))
  287. elif [ "$prev" = "=" ] ; then
  288. key=${words[$cword - 2]} # key=value case
  289. glob_pos=$((cword - 3))
  290. else
  291. return
  292. fi
  293. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  294. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  295. }
  296. # Returns the value of the first option matching option_glob.
  297. # Valid values for option_glob are option names like '--log-level' and
  298. # globs like '--log-level|-l'
  299. # Only positions between the command and the current word are considered.
  300. __docker_value_of_option() {
  301. local option_extglob=$(__docker_to_extglob "$1")
  302. local counter=$((command_pos + 1))
  303. while [ $counter -lt $cword ]; do
  304. case ${words[$counter]} in
  305. $option_extglob )
  306. echo ${words[$counter + 1]}
  307. break
  308. ;;
  309. esac
  310. (( counter++ ))
  311. done
  312. }
  313. # Transforms a multiline list of strings into a single line string
  314. # with the words separated by "|".
  315. # This is used to prepare arguments to __docker_pos_first_nonflag().
  316. __docker_to_alternatives() {
  317. local parts=( $1 )
  318. local IFS='|'
  319. echo "${parts[*]}"
  320. }
  321. # Transforms a multiline list of options into an extglob pattern
  322. # suitable for use in case statements.
  323. __docker_to_extglob() {
  324. local extglob=$( __docker_to_alternatives "$1" )
  325. echo "@($extglob)"
  326. }
  327. # Subcommand processing.
  328. # Locates the first occurrence of any of the subcommands contained in the
  329. # first argument. In case of a match, calls the corresponding completion
  330. # function and returns 0.
  331. # If no match is found, 1 is returned. The calling function can then
  332. # continue processing its completion.
  333. #
  334. # TODO if the preceding command has options that accept arguments and an
  335. # argument is equal ot one of the subcommands, this is falsely detected as
  336. # a match.
  337. __docker_subcommands() {
  338. local subcommands="$1"
  339. local counter=$(($command_pos + 1))
  340. while [ $counter -lt $cword ]; do
  341. case "${words[$counter]}" in
  342. $(__docker_to_extglob "$subcommands") )
  343. subcommand_pos=$counter
  344. local subcommand=${words[$counter]}
  345. local completions_func=_docker_${command}_${subcommand}
  346. declare -F $completions_func >/dev/null && $completions_func
  347. return 0
  348. ;;
  349. esac
  350. (( counter++ ))
  351. done
  352. return 1
  353. }
  354. # suppress trailing whitespace
  355. __docker_nospace() {
  356. # compopt is not available in ancient bash versions
  357. type compopt &>/dev/null && compopt -o nospace
  358. }
  359. __docker_complete_resolved_hostname() {
  360. command -v host >/dev/null 2>&1 || return
  361. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  362. }
  363. __docker_complete_capabilities() {
  364. # The list of capabilities is defined in types.go, ALL was added manually.
  365. COMPREPLY=( $( compgen -W "
  366. ALL
  367. AUDIT_CONTROL
  368. AUDIT_WRITE
  369. AUDIT_READ
  370. BLOCK_SUSPEND
  371. CHOWN
  372. DAC_OVERRIDE
  373. DAC_READ_SEARCH
  374. FOWNER
  375. FSETID
  376. IPC_LOCK
  377. IPC_OWNER
  378. KILL
  379. LEASE
  380. LINUX_IMMUTABLE
  381. MAC_ADMIN
  382. MAC_OVERRIDE
  383. MKNOD
  384. NET_ADMIN
  385. NET_BIND_SERVICE
  386. NET_BROADCAST
  387. NET_RAW
  388. SETFCAP
  389. SETGID
  390. SETPCAP
  391. SETUID
  392. SYS_ADMIN
  393. SYS_BOOT
  394. SYS_CHROOT
  395. SYSLOG
  396. SYS_MODULE
  397. SYS_NICE
  398. SYS_PACCT
  399. SYS_PTRACE
  400. SYS_RAWIO
  401. SYS_RESOURCE
  402. SYS_TIME
  403. SYS_TTY_CONFIG
  404. WAKE_ALARM
  405. " -- "$cur" ) )
  406. }
  407. __docker_complete_detach-keys() {
  408. case "$prev" in
  409. --detach-keys)
  410. case "$cur" in
  411. *,)
  412. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  413. ;;
  414. *)
  415. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  416. ;;
  417. esac
  418. __docker_nospace
  419. return
  420. ;;
  421. esac
  422. return 1
  423. }
  424. __docker_complete_isolation() {
  425. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  426. }
  427. __docker_complete_log_drivers() {
  428. COMPREPLY=( $( compgen -W "
  429. awslogs
  430. etwlogs
  431. fluentd
  432. gcplogs
  433. gelf
  434. journald
  435. json-file
  436. none
  437. splunk
  438. syslog
  439. " -- "$cur" ) )
  440. }
  441. __docker_complete_log_options() {
  442. # see docs/reference/logging/index.md
  443. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  444. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  445. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  446. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  447. local journald_options="env labels tag"
  448. local json_file_options="env labels max-file max-size"
  449. local syslog_options="syslog-address syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify syslog-facility tag"
  450. local splunk_options="env labels splunk-caname splunk-capath splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url tag"
  451. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  452. case $(__docker_value_of_option --log-driver) in
  453. '')
  454. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  455. ;;
  456. awslogs)
  457. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  458. ;;
  459. fluentd)
  460. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  461. ;;
  462. gcplogs)
  463. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  464. ;;
  465. gelf)
  466. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  467. ;;
  468. journald)
  469. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  470. ;;
  471. json-file)
  472. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  473. ;;
  474. syslog)
  475. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  476. ;;
  477. splunk)
  478. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  479. ;;
  480. *)
  481. return
  482. ;;
  483. esac
  484. __docker_nospace
  485. }
  486. __docker_complete_log_driver_options() {
  487. local key=$(__docker_map_key_of_current_option '--log-opt')
  488. case "$key" in
  489. fluentd-async-connect)
  490. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  491. return
  492. ;;
  493. gelf-address)
  494. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  495. __docker_nospace
  496. return
  497. ;;
  498. gelf-compression-level)
  499. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  500. return
  501. ;;
  502. gelf-compression-type)
  503. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  504. return
  505. ;;
  506. syslog-address)
  507. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  508. __docker_nospace
  509. __ltrim_colon_completions "${cur}"
  510. return
  511. ;;
  512. syslog-facility)
  513. COMPREPLY=( $( compgen -W "
  514. auth
  515. authpriv
  516. cron
  517. daemon
  518. ftp
  519. kern
  520. local0
  521. local1
  522. local2
  523. local3
  524. local4
  525. local5
  526. local6
  527. local7
  528. lpr
  529. mail
  530. news
  531. syslog
  532. user
  533. uucp
  534. " -- "${cur##*=}" ) )
  535. return
  536. ;;
  537. syslog-format)
  538. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  539. return
  540. ;;
  541. syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key)
  542. _filedir
  543. return
  544. ;;
  545. syslog-tls-skip-verify)
  546. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  547. return
  548. ;;
  549. splunk-url)
  550. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  551. __docker_nospace
  552. __ltrim_colon_completions "${cur}"
  553. return
  554. ;;
  555. splunk-insecureskipverify)
  556. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  557. return
  558. ;;
  559. esac
  560. return 1
  561. }
  562. __docker_complete_log_levels() {
  563. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  564. }
  565. __docker_complete_restart() {
  566. case "$prev" in
  567. --restart)
  568. case "$cur" in
  569. on-failure:*)
  570. ;;
  571. *)
  572. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  573. ;;
  574. esac
  575. return
  576. ;;
  577. esac
  578. return 1
  579. }
  580. # a selection of the available signals that is most likely of interest in the
  581. # context of docker containers.
  582. __docker_complete_signals() {
  583. local signals=(
  584. SIGCONT
  585. SIGHUP
  586. SIGINT
  587. SIGKILL
  588. SIGQUIT
  589. SIGSTOP
  590. SIGTERM
  591. SIGUSR1
  592. SIGUSR2
  593. )
  594. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  595. }
  596. __docker_complete_user_group() {
  597. if [[ $cur == *:* ]] ; then
  598. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  599. else
  600. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  601. __docker_nospace
  602. fi
  603. }
  604. # global options that may appear after the docker command
  605. _docker_docker() {
  606. local boolean_options="
  607. $global_boolean_options
  608. --help
  609. --version -v
  610. "
  611. case "$prev" in
  612. --config)
  613. _filedir -d
  614. return
  615. ;;
  616. --log-level|-l)
  617. __docker_complete_log_levels
  618. return
  619. ;;
  620. $(__docker_to_extglob "$global_options_with_args") )
  621. return
  622. ;;
  623. esac
  624. case "$cur" in
  625. -*)
  626. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  627. ;;
  628. *)
  629. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  630. if [ $cword -eq $counter ]; then
  631. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  632. fi
  633. ;;
  634. esac
  635. }
  636. _docker_attach() {
  637. __docker_complete_detach-keys && return
  638. case "$cur" in
  639. -*)
  640. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  641. ;;
  642. *)
  643. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  644. if [ $cword -eq $counter ]; then
  645. __docker_complete_containers_running
  646. fi
  647. ;;
  648. esac
  649. }
  650. _docker_build() {
  651. local options_with_args="
  652. --build-arg
  653. --cgroup-parent
  654. --cpuset-cpus
  655. --cpuset-mems
  656. --cpu-shares -c
  657. --cpu-period
  658. --cpu-quota
  659. --file -f
  660. --isolation
  661. --label
  662. --memory -m
  663. --memory-swap
  664. --shm-size
  665. --tag -t
  666. --ulimit
  667. "
  668. local boolean_options="
  669. --disable-content-trust=false
  670. --force-rm
  671. --help
  672. --no-cache
  673. --pull
  674. --quiet -q
  675. --rm
  676. "
  677. local all_options="$options_with_args $boolean_options"
  678. case "$prev" in
  679. --build-arg)
  680. COMPREPLY=( $( compgen -e -- "$cur" ) )
  681. __docker_nospace
  682. return
  683. ;;
  684. --file|-f)
  685. _filedir
  686. return
  687. ;;
  688. --isolation)
  689. __docker_complete_isolation
  690. return
  691. ;;
  692. --tag|-t)
  693. __docker_complete_image_repos_and_tags
  694. return
  695. ;;
  696. $(__docker_to_extglob "$options_with_args") )
  697. return
  698. ;;
  699. esac
  700. case "$cur" in
  701. -*)
  702. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  703. ;;
  704. *)
  705. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  706. if [ $cword -eq $counter ]; then
  707. _filedir -d
  708. fi
  709. ;;
  710. esac
  711. }
  712. _docker_commit() {
  713. case "$prev" in
  714. --author|-a|--change|-c|--message|-m)
  715. return
  716. ;;
  717. esac
  718. case "$cur" in
  719. -*)
  720. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  721. ;;
  722. *)
  723. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  724. if [ $cword -eq $counter ]; then
  725. __docker_complete_containers_all
  726. return
  727. fi
  728. (( counter++ ))
  729. if [ $cword -eq $counter ]; then
  730. __docker_complete_image_repos_and_tags
  731. return
  732. fi
  733. ;;
  734. esac
  735. }
  736. _docker_cp() {
  737. case "$cur" in
  738. -*)
  739. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  740. ;;
  741. *)
  742. local counter=$(__docker_pos_first_nonflag)
  743. if [ $cword -eq $counter ]; then
  744. case "$cur" in
  745. *:)
  746. return
  747. ;;
  748. *)
  749. # combined container and filename completion
  750. _filedir
  751. local files=( ${COMPREPLY[@]} )
  752. __docker_complete_containers_all
  753. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  754. local containers=( ${COMPREPLY[@]} )
  755. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  756. if [[ "$COMPREPLY" == *: ]]; then
  757. __docker_nospace
  758. fi
  759. return
  760. ;;
  761. esac
  762. fi
  763. (( counter++ ))
  764. if [ $cword -eq $counter ]; then
  765. if [ -e "$prev" ]; then
  766. __docker_complete_containers_all
  767. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  768. __docker_nospace
  769. else
  770. _filedir
  771. fi
  772. return
  773. fi
  774. ;;
  775. esac
  776. }
  777. _docker_create() {
  778. _docker_run
  779. }
  780. _docker_daemon() {
  781. local boolean_options="
  782. $global_boolean_options
  783. --disable-legacy-registry
  784. --help
  785. --icc=false
  786. --ip-forward=false
  787. --ip-masq=false
  788. --iptables=false
  789. --ipv6
  790. --live-restore
  791. --raw-logs
  792. --selinux-enabled
  793. --userland-proxy=false
  794. "
  795. local options_with_args="
  796. $global_options_with_args
  797. --add-runtime
  798. --api-cors-header
  799. --authorization-plugin
  800. --bip
  801. --bridge -b
  802. --cgroup-parent
  803. --cluster-advertise
  804. --cluster-store
  805. --cluster-store-opt
  806. --config-file
  807. --containerd
  808. --default-gateway
  809. --default-gateway-v6
  810. --default-ulimit
  811. --dns
  812. --dns-search
  813. --dns-opt
  814. --exec-opt
  815. --exec-root
  816. --fixed-cidr
  817. --fixed-cidr-v6
  818. --graph -g
  819. --group -G
  820. --insecure-registry
  821. --ip
  822. --label
  823. --log-driver
  824. --log-opt
  825. --max-concurrent-downloads
  826. --max-concurrent-uploads
  827. --mtu
  828. --pidfile -p
  829. --registry-mirror
  830. --storage-driver -s
  831. --storage-opt
  832. --userns-remap
  833. "
  834. __docker_complete_log_driver_options && return
  835. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  836. case "$key" in
  837. kv.*file)
  838. cur=${cur##*=}
  839. _filedir
  840. return
  841. ;;
  842. esac
  843. local key=$(__docker_map_key_of_current_option '--storage-opt')
  844. case "$key" in
  845. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  846. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  847. return
  848. ;;
  849. dm.fs)
  850. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  851. return
  852. ;;
  853. dm.thinpooldev)
  854. cur=${cur##*=}
  855. _filedir
  856. return
  857. ;;
  858. esac
  859. case "$prev" in
  860. --authorization-plugin)
  861. __docker_complete_plugins Authorization
  862. return
  863. ;;
  864. --cluster-store)
  865. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  866. __docker_nospace
  867. return
  868. ;;
  869. --cluster-store-opt)
  870. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  871. __docker_nospace
  872. return
  873. ;;
  874. --exec-root|--graph|-g)
  875. _filedir -d
  876. return
  877. ;;
  878. --log-driver)
  879. __docker_complete_log_drivers
  880. return
  881. ;;
  882. --config-file|--containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  883. _filedir
  884. return
  885. ;;
  886. --storage-driver|-s)
  887. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  888. return
  889. ;;
  890. --storage-opt)
  891. local btrfs_options="btrfs.min_space"
  892. local devicemapper_options="
  893. dm.basesize
  894. dm.blkdiscard
  895. dm.blocksize
  896. dm.fs
  897. dm.loopdatasize
  898. dm.loopmetadatasize
  899. dm.min_free_space
  900. dm.mkfsarg
  901. dm.mountopt
  902. dm.override_udev_sync_check
  903. dm.thinpooldev
  904. dm.use_deferred_deletion
  905. dm.use_deferred_removal
  906. "
  907. local zfs_options="zfs.fsname"
  908. case $(__docker_value_of_option '--storage-driver|-s') in
  909. '')
  910. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  911. ;;
  912. btrfs)
  913. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  914. ;;
  915. devicemapper)
  916. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  917. ;;
  918. zfs)
  919. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  920. ;;
  921. *)
  922. return
  923. ;;
  924. esac
  925. __docker_nospace
  926. return
  927. ;;
  928. --log-level|-l)
  929. __docker_complete_log_levels
  930. return
  931. ;;
  932. --log-opt)
  933. __docker_complete_log_options
  934. return
  935. ;;
  936. --userns-remap)
  937. __docker_complete_user_group
  938. return
  939. ;;
  940. $(__docker_to_extglob "$options_with_args") )
  941. return
  942. ;;
  943. esac
  944. case "$cur" in
  945. -*)
  946. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  947. ;;
  948. esac
  949. }
  950. _docker_diff() {
  951. case "$cur" in
  952. -*)
  953. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  954. ;;
  955. *)
  956. local counter=$(__docker_pos_first_nonflag)
  957. if [ $cword -eq $counter ]; then
  958. __docker_complete_containers_all
  959. fi
  960. ;;
  961. esac
  962. }
  963. _docker_events() {
  964. local key=$(__docker_map_key_of_current_option '-f|--filter')
  965. case "$key" in
  966. container)
  967. cur="${cur##*=}"
  968. __docker_complete_containers_all
  969. return
  970. ;;
  971. daemon)
  972. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  973. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  974. return
  975. ;;
  976. event)
  977. COMPREPLY=( $( compgen -W "
  978. attach
  979. commit
  980. connect
  981. copy
  982. create
  983. delete
  984. destroy
  985. detach
  986. die
  987. disconnect
  988. exec_create
  989. exec_detach
  990. exec_start
  991. export
  992. import
  993. kill
  994. load
  995. mount
  996. oom
  997. pause
  998. pull
  999. push
  1000. reload
  1001. rename
  1002. resize
  1003. restart
  1004. save
  1005. start
  1006. stop
  1007. tag
  1008. top
  1009. unmount
  1010. unpause
  1011. untag
  1012. update
  1013. " -- "${cur##*=}" ) )
  1014. return
  1015. ;;
  1016. image)
  1017. cur="${cur##*=}"
  1018. __docker_complete_images
  1019. return
  1020. ;;
  1021. network)
  1022. cur="${cur##*=}"
  1023. __docker_complete_networks
  1024. return
  1025. ;;
  1026. type)
  1027. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  1028. return
  1029. ;;
  1030. volume)
  1031. cur="${cur##*=}"
  1032. __docker_complete_volumes
  1033. return
  1034. ;;
  1035. esac
  1036. case "$prev" in
  1037. --filter|-f)
  1038. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  1039. __docker_nospace
  1040. return
  1041. ;;
  1042. --since|--until)
  1043. return
  1044. ;;
  1045. esac
  1046. case "$cur" in
  1047. -*)
  1048. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  1049. ;;
  1050. esac
  1051. }
  1052. _docker_exec() {
  1053. __docker_complete_detach-keys && return
  1054. case "$prev" in
  1055. --user|-u)
  1056. __docker_complete_user_group
  1057. return
  1058. ;;
  1059. esac
  1060. case "$cur" in
  1061. -*)
  1062. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  1063. ;;
  1064. *)
  1065. __docker_complete_containers_running
  1066. ;;
  1067. esac
  1068. }
  1069. _docker_export() {
  1070. case "$cur" in
  1071. -*)
  1072. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1073. ;;
  1074. *)
  1075. local counter=$(__docker_pos_first_nonflag)
  1076. if [ $cword -eq $counter ]; then
  1077. __docker_complete_containers_all
  1078. fi
  1079. ;;
  1080. esac
  1081. }
  1082. _docker_help() {
  1083. local counter=$(__docker_pos_first_nonflag)
  1084. if [ $cword -eq $counter ]; then
  1085. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1086. fi
  1087. }
  1088. _docker_history() {
  1089. case "$cur" in
  1090. -*)
  1091. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1092. ;;
  1093. *)
  1094. local counter=$(__docker_pos_first_nonflag)
  1095. if [ $cword -eq $counter ]; then
  1096. __docker_complete_images
  1097. fi
  1098. ;;
  1099. esac
  1100. }
  1101. _docker_images() {
  1102. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1103. case "$key" in
  1104. before)
  1105. cur="${cur##*=}"
  1106. __docker_complete_images
  1107. return
  1108. ;;
  1109. dangling)
  1110. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1111. return
  1112. ;;
  1113. label)
  1114. return
  1115. ;;
  1116. since)
  1117. cur="${cur##*=}"
  1118. __docker_complete_images
  1119. return
  1120. ;;
  1121. esac
  1122. case "$prev" in
  1123. --filter|-f)
  1124. COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
  1125. __docker_nospace
  1126. return
  1127. ;;
  1128. --format)
  1129. return
  1130. ;;
  1131. esac
  1132. case "$cur" in
  1133. -*)
  1134. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1135. ;;
  1136. =)
  1137. return
  1138. ;;
  1139. *)
  1140. __docker_complete_image_repos
  1141. ;;
  1142. esac
  1143. }
  1144. _docker_import() {
  1145. case "$prev" in
  1146. --change|-c|--message|-m)
  1147. return
  1148. ;;
  1149. esac
  1150. case "$cur" in
  1151. -*)
  1152. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1153. ;;
  1154. *)
  1155. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1156. if [ $cword -eq $counter ]; then
  1157. return
  1158. fi
  1159. (( counter++ ))
  1160. if [ $cword -eq $counter ]; then
  1161. __docker_complete_image_repos_and_tags
  1162. return
  1163. fi
  1164. ;;
  1165. esac
  1166. }
  1167. _docker_info() {
  1168. case "$cur" in
  1169. -*)
  1170. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1171. ;;
  1172. esac
  1173. }
  1174. _docker_inspect() {
  1175. case "$prev" in
  1176. --format|-f)
  1177. return
  1178. ;;
  1179. --type)
  1180. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1181. return
  1182. ;;
  1183. esac
  1184. case "$cur" in
  1185. -*)
  1186. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1187. ;;
  1188. *)
  1189. case $(__docker_value_of_option --type) in
  1190. '')
  1191. __docker_complete_containers_and_images
  1192. ;;
  1193. container)
  1194. __docker_complete_containers_all
  1195. ;;
  1196. image)
  1197. __docker_complete_images
  1198. ;;
  1199. esac
  1200. esac
  1201. }
  1202. _docker_kill() {
  1203. case "$prev" in
  1204. --signal|-s)
  1205. __docker_complete_signals
  1206. return
  1207. ;;
  1208. esac
  1209. case "$cur" in
  1210. -*)
  1211. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1212. ;;
  1213. *)
  1214. __docker_complete_containers_running
  1215. ;;
  1216. esac
  1217. }
  1218. _docker_load() {
  1219. case "$prev" in
  1220. --input|-i)
  1221. _filedir
  1222. return
  1223. ;;
  1224. esac
  1225. case "$cur" in
  1226. -*)
  1227. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1228. ;;
  1229. esac
  1230. }
  1231. _docker_login() {
  1232. case "$prev" in
  1233. --password|-p|--username|-u)
  1234. return
  1235. ;;
  1236. esac
  1237. case "$cur" in
  1238. -*)
  1239. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1240. ;;
  1241. esac
  1242. }
  1243. _docker_logout() {
  1244. case "$cur" in
  1245. -*)
  1246. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1247. ;;
  1248. esac
  1249. }
  1250. _docker_logs() {
  1251. case "$prev" in
  1252. --since|--tail)
  1253. return
  1254. ;;
  1255. esac
  1256. case "$cur" in
  1257. -*)
  1258. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1259. ;;
  1260. *)
  1261. local counter=$(__docker_pos_first_nonflag '--tail')
  1262. if [ $cword -eq $counter ]; then
  1263. __docker_complete_containers_all
  1264. fi
  1265. ;;
  1266. esac
  1267. }
  1268. _docker_network_connect() {
  1269. local options_with_args="
  1270. --alias
  1271. --ip
  1272. --ip6
  1273. --link
  1274. --link-local-ip
  1275. "
  1276. local boolean_options="
  1277. --help
  1278. "
  1279. case "$prev" in
  1280. --link)
  1281. case "$cur" in
  1282. *:*)
  1283. ;;
  1284. *)
  1285. __docker_complete_containers_running
  1286. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1287. __docker_nospace
  1288. ;;
  1289. esac
  1290. return
  1291. ;;
  1292. $(__docker_to_extglob "$options_with_args") )
  1293. return
  1294. ;;
  1295. esac
  1296. case "$cur" in
  1297. -*)
  1298. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1299. ;;
  1300. *)
  1301. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1302. if [ $cword -eq $counter ]; then
  1303. __docker_complete_networks
  1304. elif [ $cword -eq $(($counter + 1)) ]; then
  1305. __docker_complete_containers_all
  1306. fi
  1307. ;;
  1308. esac
  1309. }
  1310. _docker_network_create() {
  1311. case "$prev" in
  1312. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1313. return
  1314. ;;
  1315. --ipam-driver)
  1316. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1317. return
  1318. ;;
  1319. --driver|-d)
  1320. local plugins=" $(__docker_plugins Network) "
  1321. # remove drivers that allow one instance only
  1322. plugins=${plugins/ host / }
  1323. plugins=${plugins/ null / }
  1324. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1325. return
  1326. ;;
  1327. --label)
  1328. return
  1329. ;;
  1330. esac
  1331. case "$cur" in
  1332. -*)
  1333. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1334. ;;
  1335. esac
  1336. }
  1337. _docker_network_disconnect() {
  1338. case "$cur" in
  1339. -*)
  1340. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1341. ;;
  1342. *)
  1343. local counter=$(__docker_pos_first_nonflag)
  1344. if [ $cword -eq $counter ]; then
  1345. __docker_complete_networks
  1346. elif [ $cword -eq $(($counter + 1)) ]; then
  1347. __docker_complete_containers_in_network "$prev"
  1348. fi
  1349. ;;
  1350. esac
  1351. }
  1352. _docker_network_inspect() {
  1353. case "$prev" in
  1354. --format|-f)
  1355. return
  1356. ;;
  1357. esac
  1358. case "$cur" in
  1359. -*)
  1360. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1361. ;;
  1362. *)
  1363. __docker_complete_networks
  1364. esac
  1365. }
  1366. _docker_network_ls() {
  1367. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1368. case "$key" in
  1369. driver)
  1370. local plugins=" $(__docker_plugins Network) "
  1371. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1372. return
  1373. ;;
  1374. id)
  1375. cur="${cur##*=}"
  1376. __docker_complete_network_ids
  1377. return
  1378. ;;
  1379. name)
  1380. cur="${cur##*=}"
  1381. __docker_complete_network_names
  1382. return
  1383. ;;
  1384. type)
  1385. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1386. return
  1387. ;;
  1388. esac
  1389. case "$prev" in
  1390. --filter|-f)
  1391. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1392. __docker_nospace
  1393. return
  1394. ;;
  1395. esac
  1396. case "$cur" in
  1397. -*)
  1398. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1399. ;;
  1400. esac
  1401. }
  1402. _docker_network_rm() {
  1403. case "$cur" in
  1404. -*)
  1405. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1406. ;;
  1407. *)
  1408. __docker_complete_networks type=custom
  1409. esac
  1410. }
  1411. _docker_network() {
  1412. local subcommands="
  1413. connect
  1414. create
  1415. disconnect
  1416. inspect
  1417. ls
  1418. rm
  1419. "
  1420. __docker_subcommands "$subcommands" && return
  1421. case "$cur" in
  1422. -*)
  1423. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1424. ;;
  1425. *)
  1426. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1427. ;;
  1428. esac
  1429. }
  1430. _docker_service() {
  1431. local subcommands="
  1432. create
  1433. inspect
  1434. ls list
  1435. rm remove
  1436. scale
  1437. tasks
  1438. update
  1439. "
  1440. __docker_subcommands "$subcommands" && return
  1441. case "$cur" in
  1442. -*)
  1443. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1444. ;;
  1445. *)
  1446. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1447. ;;
  1448. esac
  1449. }
  1450. _docker_service_create() {
  1451. _docker_service_update
  1452. }
  1453. _docker_service_inspect() {
  1454. case "$prev" in
  1455. --format|-f)
  1456. return
  1457. ;;
  1458. esac
  1459. case "$cur" in
  1460. -*)
  1461. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1462. ;;
  1463. *)
  1464. __docker_complete_services
  1465. esac
  1466. }
  1467. _docker_service_list() {
  1468. _docker_service_ls
  1469. }
  1470. _docker_service_ls() {
  1471. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1472. case "$key" in
  1473. id)
  1474. __docker_complete_services --cur "${cur##*=}" --id
  1475. return
  1476. ;;
  1477. name)
  1478. __docker_complete_services --cur "${cur##*=}" --name
  1479. return
  1480. ;;
  1481. esac
  1482. case "$prev" in
  1483. --filter|-f)
  1484. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1485. __docker_nospace
  1486. return
  1487. ;;
  1488. esac
  1489. case "$cur" in
  1490. -*)
  1491. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1492. ;;
  1493. esac
  1494. }
  1495. _docker_service_remove() {
  1496. _docker_service_rm
  1497. }
  1498. _docker_service_rm() {
  1499. case "$cur" in
  1500. -*)
  1501. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1502. ;;
  1503. *)
  1504. __docker_complete_services
  1505. esac
  1506. }
  1507. _docker_service_scale() {
  1508. case "$cur" in
  1509. -*)
  1510. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1511. ;;
  1512. *)
  1513. __docker_complete_services
  1514. __docker_append_to_completions "="
  1515. __docker_nospace
  1516. ;;
  1517. esac
  1518. }
  1519. _docker_service_tasks() {
  1520. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1521. case "$key" in
  1522. desired-state)
  1523. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1524. return
  1525. ;;
  1526. name)
  1527. __docker_complete_services --cur "${cur##*=}" --name
  1528. return
  1529. ;;
  1530. esac
  1531. case "$prev" in
  1532. --filter|-f)
  1533. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  1534. __docker_nospace
  1535. return
  1536. ;;
  1537. esac
  1538. case "$cur" in
  1539. -*)
  1540. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) )
  1541. ;;
  1542. *)
  1543. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1544. if [ $cword -eq $counter ]; then
  1545. __docker_complete_services
  1546. fi
  1547. ;;
  1548. esac
  1549. }
  1550. _docker_service_update() {
  1551. local $subcommand="${words[$subcommand_pos]}"
  1552. local options_with_args="
  1553. --constraint
  1554. --endpoint-mode
  1555. --env -e
  1556. --label -l
  1557. --limit-cpu
  1558. --limit-memory
  1559. --mount
  1560. --name
  1561. --network
  1562. --publish -p
  1563. --replicas
  1564. --reserve-cpu
  1565. --reserve-memory
  1566. --restart-condition
  1567. --restart-delay
  1568. --restart-max-attempts
  1569. --restart-window
  1570. --stop-grace-period
  1571. --update-delay
  1572. --update-parallelism
  1573. --user -u
  1574. --workdir -w
  1575. "
  1576. local boolean_options="
  1577. --help
  1578. --registry-auth
  1579. "
  1580. if [ "$subcommand" = "create" ] ; then
  1581. options_with_args="$options_with_args
  1582. --mode
  1583. "
  1584. case "$prev" in
  1585. --mode)
  1586. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  1587. return
  1588. ;;
  1589. esac
  1590. fi
  1591. if [ "$subcommand" = "update" ] ; then
  1592. options_with_args="$options_with_args
  1593. --arg
  1594. --image
  1595. "
  1596. case "$prev" in
  1597. --image)
  1598. __docker_complete_image_repos_and_tags
  1599. return
  1600. ;;
  1601. esac
  1602. fi
  1603. case "$prev" in
  1604. --endpoint-mode)
  1605. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  1606. return
  1607. ;;
  1608. --env|-e)
  1609. COMPREPLY=( $( compgen -e -S = -- "$cur" ) )
  1610. __docker_nospace
  1611. return
  1612. ;;
  1613. --network)
  1614. __docker_complete_networks
  1615. return
  1616. ;;
  1617. --restart-condition)
  1618. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  1619. return
  1620. ;;
  1621. --user|-u)
  1622. __docker_complete_user_group
  1623. return
  1624. ;;
  1625. $(__docker_to_extglob "$options_with_args") )
  1626. return
  1627. ;;
  1628. esac
  1629. case "$cur" in
  1630. -*)
  1631. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1632. ;;
  1633. *)
  1634. if [ "$subcommand" = "update" ] ; then
  1635. __docker_complete_services
  1636. fi
  1637. esac
  1638. }
  1639. _docker_swarm() {
  1640. local subcommands="
  1641. init
  1642. inspect
  1643. join
  1644. leave
  1645. update
  1646. "
  1647. __docker_subcommands "$subcommands" && return
  1648. case "$cur" in
  1649. -*)
  1650. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1651. ;;
  1652. *)
  1653. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1654. ;;
  1655. esac
  1656. }
  1657. _docker_swarm_init() {
  1658. case "$prev" in
  1659. --auto-accept)
  1660. COMPREPLY=( $( compgen -W "manager none worker" -- "$cur" ) )
  1661. return
  1662. ;;
  1663. --listen-addr)
  1664. if [[ $cur == *: ]] ; then
  1665. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1666. fi
  1667. return
  1668. ;;
  1669. --secret)
  1670. return
  1671. ;;
  1672. esac
  1673. case "$cur" in
  1674. -*)
  1675. COMPREPLY=( $( compgen -W "--auto-accept --force-new-cluster --help --listen-addr --secret" -- "$cur" ) )
  1676. ;;
  1677. esac
  1678. }
  1679. _docker_swarm_inspect() {
  1680. case "$prev" in
  1681. --format|-f)
  1682. return
  1683. ;;
  1684. esac
  1685. case "$cur" in
  1686. -*)
  1687. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1688. ;;
  1689. esac
  1690. }
  1691. _docker_swarm_join() {
  1692. case "$prev" in
  1693. --ca-hash|--secret)
  1694. return
  1695. ;;
  1696. --listen-addr)
  1697. if [[ $cur == *: ]] ; then
  1698. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1699. fi
  1700. return
  1701. ;;
  1702. esac
  1703. case "$cur" in
  1704. -*)
  1705. COMPREPLY=( $( compgen -W "--ca-hash --help --listen-addr --manager --secret" -- "$cur" ) )
  1706. ;;
  1707. *:)
  1708. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  1709. ;;
  1710. esac
  1711. }
  1712. _docker_swarm_leave() {
  1713. case "$cur" in
  1714. -*)
  1715. COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) )
  1716. ;;
  1717. esac
  1718. }
  1719. _docker_swarm_update() {
  1720. case "$prev" in
  1721. --auto-accept)
  1722. COMPREPLY=( $( compgen -W "manager none worker" -- "$cur" ) )
  1723. return
  1724. ;;
  1725. --cert-expiry|--dispatcher-heartbeat|--secret|--task-history-limit)
  1726. return
  1727. ;;
  1728. esac
  1729. case "$cur" in
  1730. -*)
  1731. COMPREPLY=( $( compgen -W "--auto-accept --cert-expiry --dispatcher-heartbeat --help --secret --task-history-limit" -- "$cur" ) )
  1732. ;;
  1733. esac
  1734. }
  1735. _docker_node() {
  1736. local subcommands="
  1737. accept
  1738. demote
  1739. inspect
  1740. ls list
  1741. promote
  1742. rm remove
  1743. tasks
  1744. update
  1745. "
  1746. __docker_subcommands "$subcommands" && return
  1747. case "$cur" in
  1748. -*)
  1749. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1750. ;;
  1751. *)
  1752. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1753. ;;
  1754. esac
  1755. }
  1756. _docker_node_accept() {
  1757. case "$cur" in
  1758. -*)
  1759. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1760. ;;
  1761. *)
  1762. __docker_complete_nodes --id --filter membership=pending
  1763. esac
  1764. }
  1765. _docker_node_demote() {
  1766. case "$cur" in
  1767. -*)
  1768. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1769. ;;
  1770. *)
  1771. __docker_complete_nodes --filter role=manager
  1772. esac
  1773. }
  1774. _docker_node_inspect() {
  1775. case "$prev" in
  1776. --format|-f)
  1777. return
  1778. ;;
  1779. esac
  1780. case "$cur" in
  1781. -*)
  1782. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  1783. ;;
  1784. *)
  1785. __docker_complete_nodes
  1786. esac
  1787. }
  1788. _docker_node_list() {
  1789. _docker_node_ls
  1790. }
  1791. _docker_node_ls() {
  1792. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1793. case "$key" in
  1794. id)
  1795. __docker_complete_nodes --cur "${cur##*=}" --id
  1796. return
  1797. ;;
  1798. name)
  1799. __docker_complete_nodes --cur "${cur##*=}" --name
  1800. return
  1801. ;;
  1802. esac
  1803. case "$prev" in
  1804. --filter|-f)
  1805. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  1806. __docker_nospace
  1807. return
  1808. ;;
  1809. esac
  1810. case "$cur" in
  1811. -*)
  1812. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1813. ;;
  1814. esac
  1815. }
  1816. _docker_node_promote() {
  1817. case "$cur" in
  1818. -*)
  1819. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1820. ;;
  1821. *)
  1822. __docker_complete_nodes --filter role=worker
  1823. esac
  1824. }
  1825. _docker_node_remove() {
  1826. _docker_node_rm
  1827. }
  1828. _docker_node_rm() {
  1829. case "$cur" in
  1830. -*)
  1831. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1832. ;;
  1833. *)
  1834. __docker_complete_nodes
  1835. esac
  1836. }
  1837. _docker_node_tasks() {
  1838. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1839. case "$key" in
  1840. desired-state)
  1841. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  1842. return
  1843. ;;
  1844. name)
  1845. __docker_complete_services --cur "${cur##*=}" --name
  1846. return
  1847. ;;
  1848. esac
  1849. case "$prev" in
  1850. --filter|-f)
  1851. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  1852. __docker_nospace
  1853. return
  1854. ;;
  1855. esac
  1856. case "$cur" in
  1857. -*)
  1858. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve" -- "$cur" ) )
  1859. ;;
  1860. *)
  1861. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  1862. if [ $cword -eq $counter ]; then
  1863. __docker_complete_nodes_plus_self
  1864. fi
  1865. ;;
  1866. esac
  1867. }
  1868. _docker_node_update() {
  1869. case "$prev" in
  1870. --availability)
  1871. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  1872. return
  1873. ;;
  1874. --membership)
  1875. COMPREPLY=( $( compgen -W "accepted rejected" -- "$cur" ) )
  1876. return
  1877. ;;
  1878. --role)
  1879. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  1880. return
  1881. ;;
  1882. esac
  1883. case "$cur" in
  1884. -*)
  1885. COMPREPLY=( $( compgen -W "--availability --help --membership --role" -- "$cur" ) )
  1886. ;;
  1887. *)
  1888. __docker_complete_nodes
  1889. esac
  1890. }
  1891. _docker_pause() {
  1892. case "$cur" in
  1893. -*)
  1894. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1895. ;;
  1896. *)
  1897. local counter=$(__docker_pos_first_nonflag)
  1898. if [ $cword -eq $counter ]; then
  1899. __docker_complete_containers_pauseable
  1900. fi
  1901. ;;
  1902. esac
  1903. }
  1904. _docker_port() {
  1905. case "$cur" in
  1906. -*)
  1907. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1908. ;;
  1909. *)
  1910. local counter=$(__docker_pos_first_nonflag)
  1911. if [ $cword -eq $counter ]; then
  1912. __docker_complete_containers_all
  1913. fi
  1914. ;;
  1915. esac
  1916. }
  1917. _docker_ps() {
  1918. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1919. case "$key" in
  1920. ancestor)
  1921. cur="${cur##*=}"
  1922. __docker_complete_images
  1923. return
  1924. ;;
  1925. before)
  1926. cur="${cur##*=}"
  1927. __docker_complete_containers_all
  1928. return
  1929. ;;
  1930. id)
  1931. cur="${cur##*=}"
  1932. __docker_complete_container_ids
  1933. return
  1934. ;;
  1935. name)
  1936. cur="${cur##*=}"
  1937. __docker_complete_container_names
  1938. return
  1939. ;;
  1940. network)
  1941. cur="${cur##*=}"
  1942. __docker_complete_networks
  1943. return
  1944. ;;
  1945. since)
  1946. cur="${cur##*=}"
  1947. __docker_complete_containers_all
  1948. return
  1949. ;;
  1950. status)
  1951. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1952. return
  1953. ;;
  1954. volume)
  1955. cur="${cur##*=}"
  1956. __docker_complete_volumes
  1957. return
  1958. ;;
  1959. esac
  1960. case "$prev" in
  1961. --filter|-f)
  1962. COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) )
  1963. __docker_nospace
  1964. return
  1965. ;;
  1966. --format|--last|-n)
  1967. return
  1968. ;;
  1969. esac
  1970. case "$cur" in
  1971. -*)
  1972. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1973. ;;
  1974. esac
  1975. }
  1976. _docker_pull() {
  1977. case "$cur" in
  1978. -*)
  1979. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1980. ;;
  1981. *)
  1982. local counter=$(__docker_pos_first_nonflag)
  1983. if [ $cword -eq $counter ]; then
  1984. for arg in "${COMP_WORDS[@]}"; do
  1985. case "$arg" in
  1986. --all-tags|-a)
  1987. __docker_complete_image_repos
  1988. return
  1989. ;;
  1990. esac
  1991. done
  1992. __docker_complete_image_repos_and_tags
  1993. fi
  1994. ;;
  1995. esac
  1996. }
  1997. _docker_push() {
  1998. case "$cur" in
  1999. -*)
  2000. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2001. ;;
  2002. *)
  2003. local counter=$(__docker_pos_first_nonflag)
  2004. if [ $cword -eq $counter ]; then
  2005. __docker_complete_image_repos_and_tags
  2006. fi
  2007. ;;
  2008. esac
  2009. }
  2010. _docker_rename() {
  2011. case "$cur" in
  2012. -*)
  2013. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2014. ;;
  2015. *)
  2016. local counter=$(__docker_pos_first_nonflag)
  2017. if [ $cword -eq $counter ]; then
  2018. __docker_complete_containers_all
  2019. fi
  2020. ;;
  2021. esac
  2022. }
  2023. _docker_restart() {
  2024. case "$prev" in
  2025. --time|-t)
  2026. return
  2027. ;;
  2028. esac
  2029. case "$cur" in
  2030. -*)
  2031. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2032. ;;
  2033. *)
  2034. __docker_complete_containers_all
  2035. ;;
  2036. esac
  2037. }
  2038. _docker_rm() {
  2039. case "$cur" in
  2040. -*)
  2041. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  2042. ;;
  2043. *)
  2044. for arg in "${COMP_WORDS[@]}"; do
  2045. case "$arg" in
  2046. --force|-f)
  2047. __docker_complete_containers_all
  2048. return
  2049. ;;
  2050. esac
  2051. done
  2052. __docker_complete_containers_stopped
  2053. ;;
  2054. esac
  2055. }
  2056. _docker_rmi() {
  2057. case "$cur" in
  2058. -*)
  2059. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2060. ;;
  2061. *)
  2062. __docker_complete_images
  2063. ;;
  2064. esac
  2065. }
  2066. _docker_run() {
  2067. local options_with_args="
  2068. --add-host
  2069. --attach -a
  2070. --blkio-weight
  2071. --blkio-weight-device
  2072. --cap-add
  2073. --cap-drop
  2074. --cgroup-parent
  2075. --cidfile
  2076. --cpu-period
  2077. --cpu-quota
  2078. --cpuset-cpus
  2079. --cpuset-mems
  2080. --cpu-shares -c
  2081. --device
  2082. --device-read-bps
  2083. --device-read-iops
  2084. --device-write-bps
  2085. --device-write-iops
  2086. --dns
  2087. --dns-opt
  2088. --dns-search
  2089. --entrypoint
  2090. --env -e
  2091. --env-file
  2092. --expose
  2093. --group-add
  2094. --hostname -h
  2095. --ip
  2096. --ip6
  2097. --ipc
  2098. --isolation
  2099. --kernel-memory
  2100. --label-file
  2101. --label -l
  2102. --link
  2103. --link-local-ip
  2104. --log-driver
  2105. --log-opt
  2106. --mac-address
  2107. --memory -m
  2108. --memory-swap
  2109. --memory-swappiness
  2110. --memory-reservation
  2111. --name
  2112. --network
  2113. --network-alias
  2114. --oom-score-adj
  2115. --pid
  2116. --pids-limit
  2117. --publish -p
  2118. --restart
  2119. --runtime
  2120. --security-opt
  2121. --shm-size
  2122. --stop-signal
  2123. --storage-opt
  2124. --tmpfs
  2125. --sysctl
  2126. --ulimit
  2127. --user -u
  2128. --userns
  2129. --uts
  2130. --volume-driver
  2131. --volumes-from
  2132. --volume -v
  2133. --workdir -w
  2134. "
  2135. local boolean_options="
  2136. --disable-content-trust=false
  2137. --help
  2138. --interactive -i
  2139. --oom-kill-disable
  2140. --privileged
  2141. --publish-all -P
  2142. --read-only
  2143. --tty -t
  2144. "
  2145. if [ "$command" = "run" ] ; then
  2146. options_with_args="$options_with_args
  2147. --detach-keys
  2148. --health-cmd
  2149. --health-interval
  2150. --health-retries
  2151. --health-timeout
  2152. "
  2153. boolean_options="$boolean_options
  2154. --detach -d
  2155. --no-healthcheck
  2156. --rm
  2157. --sig-proxy=false
  2158. "
  2159. __docker_complete_detach-keys && return
  2160. fi
  2161. local all_options="$options_with_args $boolean_options"
  2162. __docker_complete_log_driver_options && return
  2163. __docker_complete_restart && return
  2164. local key=$(__docker_map_key_of_current_option '--security-opt')
  2165. case "$key" in
  2166. label)
  2167. [[ $cur == *: ]] && return
  2168. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  2169. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  2170. __docker_nospace
  2171. fi
  2172. return
  2173. ;;
  2174. seccomp)
  2175. local cur=${cur##*=}
  2176. _filedir
  2177. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  2178. return
  2179. ;;
  2180. esac
  2181. case "$prev" in
  2182. --add-host)
  2183. case "$cur" in
  2184. *:)
  2185. __docker_complete_resolved_hostname
  2186. return
  2187. ;;
  2188. esac
  2189. ;;
  2190. --attach|-a)
  2191. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  2192. return
  2193. ;;
  2194. --cap-add|--cap-drop)
  2195. __docker_complete_capabilities
  2196. return
  2197. ;;
  2198. --cidfile|--env-file|--label-file)
  2199. _filedir
  2200. return
  2201. ;;
  2202. --device|--tmpfs|--volume|-v)
  2203. case "$cur" in
  2204. *:*)
  2205. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  2206. ;;
  2207. '')
  2208. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  2209. __docker_nospace
  2210. ;;
  2211. /*)
  2212. _filedir
  2213. __docker_nospace
  2214. ;;
  2215. esac
  2216. return
  2217. ;;
  2218. --env|-e)
  2219. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2220. __docker_nospace
  2221. return
  2222. ;;
  2223. --ipc)
  2224. case "$cur" in
  2225. *:*)
  2226. cur="${cur#*:}"
  2227. __docker_complete_containers_running
  2228. ;;
  2229. *)
  2230. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2231. if [ "$COMPREPLY" = "container:" ]; then
  2232. __docker_nospace
  2233. fi
  2234. ;;
  2235. esac
  2236. return
  2237. ;;
  2238. --isolation)
  2239. __docker_complete_isolation
  2240. return
  2241. ;;
  2242. --link)
  2243. case "$cur" in
  2244. *:*)
  2245. ;;
  2246. *)
  2247. __docker_complete_containers_running
  2248. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2249. __docker_nospace
  2250. ;;
  2251. esac
  2252. return
  2253. ;;
  2254. --log-driver)
  2255. __docker_complete_log_drivers
  2256. return
  2257. ;;
  2258. --log-opt)
  2259. __docker_complete_log_options
  2260. return
  2261. ;;
  2262. --network)
  2263. case "$cur" in
  2264. container:*)
  2265. local cur=${cur#*:}
  2266. __docker_complete_containers_all
  2267. ;;
  2268. *)
  2269. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  2270. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  2271. __docker_nospace
  2272. fi
  2273. ;;
  2274. esac
  2275. return
  2276. ;;
  2277. --pid)
  2278. case "$cur" in
  2279. *:*)
  2280. cur="${cur#*:}"
  2281. __docker_complete_containers_running
  2282. ;;
  2283. *)
  2284. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  2285. if [ "$COMPREPLY" = "container:" ]; then
  2286. __docker_nospace
  2287. fi
  2288. ;;
  2289. esac
  2290. return
  2291. ;;
  2292. --runtime)
  2293. __docker_complete_runtimes
  2294. return
  2295. ;;
  2296. --security-opt)
  2297. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  2298. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  2299. __docker_nospace
  2300. fi
  2301. return
  2302. ;;
  2303. --storage-opt)
  2304. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  2305. __docker_nospace
  2306. return
  2307. ;;
  2308. --user|-u)
  2309. __docker_complete_user_group
  2310. return
  2311. ;;
  2312. --userns)
  2313. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  2314. return
  2315. ;;
  2316. --volume-driver)
  2317. __docker_complete_plugins Volume
  2318. return
  2319. ;;
  2320. --volumes-from)
  2321. __docker_complete_containers_all
  2322. return
  2323. ;;
  2324. $(__docker_to_extglob "$options_with_args") )
  2325. return
  2326. ;;
  2327. esac
  2328. case "$cur" in
  2329. -*)
  2330. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2331. ;;
  2332. *)
  2333. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2334. if [ $cword -eq $counter ]; then
  2335. __docker_complete_images
  2336. fi
  2337. ;;
  2338. esac
  2339. }
  2340. _docker_save() {
  2341. case "$prev" in
  2342. --output|-o)
  2343. _filedir
  2344. return
  2345. ;;
  2346. esac
  2347. case "$cur" in
  2348. -*)
  2349. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2350. ;;
  2351. *)
  2352. __docker_complete_images
  2353. ;;
  2354. esac
  2355. }
  2356. _docker_search() {
  2357. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2358. case "$key" in
  2359. is-automated)
  2360. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2361. return
  2362. ;;
  2363. is-official)
  2364. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  2365. return
  2366. ;;
  2367. esac
  2368. case "$prev" in
  2369. --filter|-f)
  2370. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  2371. __docker_nospace
  2372. return
  2373. ;;
  2374. --limit)
  2375. return
  2376. ;;
  2377. esac
  2378. case "$cur" in
  2379. -*)
  2380. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  2381. ;;
  2382. esac
  2383. }
  2384. _docker_start() {
  2385. __docker_complete_detach-keys && return
  2386. case "$cur" in
  2387. -*)
  2388. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  2389. ;;
  2390. *)
  2391. __docker_complete_containers_stopped
  2392. ;;
  2393. esac
  2394. }
  2395. _docker_stats() {
  2396. case "$cur" in
  2397. -*)
  2398. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  2399. ;;
  2400. *)
  2401. __docker_complete_containers_running
  2402. ;;
  2403. esac
  2404. }
  2405. _docker_stop() {
  2406. case "$prev" in
  2407. --time|-t)
  2408. return
  2409. ;;
  2410. esac
  2411. case "$cur" in
  2412. -*)
  2413. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  2414. ;;
  2415. *)
  2416. __docker_complete_containers_running
  2417. ;;
  2418. esac
  2419. }
  2420. _docker_tag() {
  2421. case "$cur" in
  2422. -*)
  2423. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2424. ;;
  2425. *)
  2426. local counter=$(__docker_pos_first_nonflag)
  2427. if [ $cword -eq $counter ]; then
  2428. __docker_complete_image_repos_and_tags
  2429. return
  2430. fi
  2431. (( counter++ ))
  2432. if [ $cword -eq $counter ]; then
  2433. __docker_complete_image_repos_and_tags
  2434. return
  2435. fi
  2436. ;;
  2437. esac
  2438. }
  2439. _docker_unpause() {
  2440. case "$cur" in
  2441. -*)
  2442. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2443. ;;
  2444. *)
  2445. local counter=$(__docker_pos_first_nonflag)
  2446. if [ $cword -eq $counter ]; then
  2447. __docker_complete_containers_unpauseable
  2448. fi
  2449. ;;
  2450. esac
  2451. }
  2452. _docker_update() {
  2453. local options_with_args="
  2454. --blkio-weight
  2455. --cpu-period
  2456. --cpu-quota
  2457. --cpuset-cpus
  2458. --cpuset-mems
  2459. --cpu-shares -c
  2460. --kernel-memory
  2461. --memory -m
  2462. --memory-reservation
  2463. --memory-swap
  2464. --restart
  2465. "
  2466. local boolean_options="
  2467. --help
  2468. "
  2469. local all_options="$options_with_args $boolean_options"
  2470. __docker_complete_restart && return
  2471. case "$prev" in
  2472. $(__docker_to_extglob "$options_with_args") )
  2473. return
  2474. ;;
  2475. esac
  2476. case "$cur" in
  2477. -*)
  2478. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  2479. ;;
  2480. *)
  2481. __docker_complete_containers_all
  2482. ;;
  2483. esac
  2484. }
  2485. _docker_top() {
  2486. case "$cur" in
  2487. -*)
  2488. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2489. ;;
  2490. *)
  2491. local counter=$(__docker_pos_first_nonflag)
  2492. if [ $cword -eq $counter ]; then
  2493. __docker_complete_containers_running
  2494. fi
  2495. ;;
  2496. esac
  2497. }
  2498. _docker_version() {
  2499. case "$cur" in
  2500. -*)
  2501. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2502. ;;
  2503. esac
  2504. }
  2505. _docker_volume_create() {
  2506. case "$prev" in
  2507. --driver|-d)
  2508. __docker_complete_plugins Volume
  2509. return
  2510. ;;
  2511. --label|--name|--opt|-o)
  2512. return
  2513. ;;
  2514. esac
  2515. case "$cur" in
  2516. -*)
  2517. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  2518. ;;
  2519. esac
  2520. }
  2521. _docker_volume_inspect() {
  2522. case "$prev" in
  2523. --format|-f)
  2524. return
  2525. ;;
  2526. esac
  2527. case "$cur" in
  2528. -*)
  2529. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2530. ;;
  2531. *)
  2532. __docker_complete_volumes
  2533. ;;
  2534. esac
  2535. }
  2536. _docker_volume_ls() {
  2537. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2538. case "$key" in
  2539. dangling)
  2540. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  2541. return
  2542. ;;
  2543. driver)
  2544. cur=${cur##*=}
  2545. __docker_complete_plugins Volume
  2546. return
  2547. ;;
  2548. name)
  2549. cur=${cur##*=}
  2550. __docker_complete_volumes
  2551. return
  2552. ;;
  2553. esac
  2554. case "$prev" in
  2555. --filter|-f)
  2556. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  2557. __docker_nospace
  2558. return
  2559. ;;
  2560. esac
  2561. case "$cur" in
  2562. -*)
  2563. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2564. ;;
  2565. esac
  2566. }
  2567. _docker_volume_rm() {
  2568. case "$cur" in
  2569. -*)
  2570. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2571. ;;
  2572. *)
  2573. __docker_complete_volumes
  2574. ;;
  2575. esac
  2576. }
  2577. _docker_volume() {
  2578. local subcommands="
  2579. create
  2580. inspect
  2581. ls
  2582. rm
  2583. "
  2584. __docker_subcommands "$subcommands" && return
  2585. case "$cur" in
  2586. -*)
  2587. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2588. ;;
  2589. *)
  2590. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2591. ;;
  2592. esac
  2593. }
  2594. _docker_wait() {
  2595. case "$cur" in
  2596. -*)
  2597. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2598. ;;
  2599. *)
  2600. __docker_complete_containers_all
  2601. ;;
  2602. esac
  2603. }
  2604. _docker() {
  2605. local previous_extglob_setting=$(shopt -p extglob)
  2606. shopt -s extglob
  2607. local commands=(
  2608. attach
  2609. build
  2610. commit
  2611. cp
  2612. create
  2613. daemon
  2614. diff
  2615. events
  2616. exec
  2617. export
  2618. history
  2619. images
  2620. import
  2621. info
  2622. inspect
  2623. kill
  2624. load
  2625. login
  2626. logout
  2627. logs
  2628. network
  2629. node
  2630. pause
  2631. port
  2632. ps
  2633. pull
  2634. push
  2635. rename
  2636. restart
  2637. rm
  2638. rmi
  2639. run
  2640. save
  2641. search
  2642. service
  2643. start
  2644. stats
  2645. stop
  2646. swarm
  2647. tag
  2648. top
  2649. unpause
  2650. update
  2651. version
  2652. volume
  2653. wait
  2654. )
  2655. # These options are valid as global options for all client commands
  2656. # and valid as command options for `docker daemon`
  2657. local global_boolean_options="
  2658. --debug -D
  2659. --tls
  2660. --tlsverify
  2661. "
  2662. local global_options_with_args="
  2663. --config
  2664. --host -H
  2665. --log-level -l
  2666. --tlscacert
  2667. --tlscert
  2668. --tlskey
  2669. "
  2670. local host config
  2671. COMPREPLY=()
  2672. local cur prev words cword
  2673. _get_comp_words_by_ref -n : cur prev words cword
  2674. local command='docker' command_pos=0 subcommand_pos
  2675. local counter=1
  2676. while [ $counter -lt $cword ]; do
  2677. case "${words[$counter]}" in
  2678. # save host so that completion can use custom daemon
  2679. --host|-H)
  2680. (( counter++ ))
  2681. host="${words[$counter]}"
  2682. ;;
  2683. # save config so that completion can use custom configuration directories
  2684. --config)
  2685. (( counter++ ))
  2686. config="${words[$counter]}"
  2687. ;;
  2688. $(__docker_to_extglob "$global_options_with_args") )
  2689. (( counter++ ))
  2690. ;;
  2691. -*)
  2692. ;;
  2693. =)
  2694. (( counter++ ))
  2695. ;;
  2696. *)
  2697. command="${words[$counter]}"
  2698. command_pos=$counter
  2699. break
  2700. ;;
  2701. esac
  2702. (( counter++ ))
  2703. done
  2704. local binary="${words[0]}"
  2705. if [[ $binary == ?(*/)dockerd ]] ; then
  2706. # for the dockerd binary, we reuse completion of `docker daemon`.
  2707. # dockerd does not have subcommands and global options.
  2708. command=daemon
  2709. command_pos=0
  2710. fi
  2711. local completions_func=_docker_${command}
  2712. declare -F $completions_func >/dev/null && $completions_func
  2713. eval "$previous_extglob_setting"
  2714. return 0
  2715. }
  2716. eval "$__docker_previous_extglob_setting"
  2717. unset __docker_previous_extglob_setting
  2718. complete -F _docker docker dockerd