docker 54 KB

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