docker 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267
  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. # Finds the position of the first word that is neither option nor an option's argument.
  166. # If there are options that require arguments, you should pass a glob describing those
  167. # options, e.g. "--option1|-o|--option2"
  168. # Use this function to restrict completions to exact positions after the argument list.
  169. __docker_pos_first_nonflag() {
  170. local argument_flags=$1
  171. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  172. while [ $counter -le $cword ]; do
  173. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  174. (( counter++ ))
  175. # eat "=" in case of --option=arg syntax
  176. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  177. else
  178. case "${words[$counter]}" in
  179. -*)
  180. ;;
  181. *)
  182. break
  183. ;;
  184. esac
  185. fi
  186. # Bash splits words at "=", retaining "=" as a word, examples:
  187. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  188. while [ "${words[$counter + 1]}" = "=" ] ; do
  189. counter=$(( counter + 2))
  190. done
  191. (( counter++ ))
  192. done
  193. echo $counter
  194. }
  195. # If we are currently completing the value of a map option (key=value)
  196. # which matches the extglob given as an argument, returns key.
  197. # This function is needed for key-specific completions.
  198. __docker_map_key_of_current_option() {
  199. local glob="$1"
  200. local key glob_pos
  201. if [ "$cur" = "=" ] ; then # key= case
  202. key="$prev"
  203. glob_pos=$((cword - 2))
  204. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  205. key=${cur%=*}
  206. glob_pos=$((cword - 1))
  207. elif [ "$prev" = "=" ] ; then
  208. key=${words[$cword - 2]} # key=value case
  209. glob_pos=$((cword - 3))
  210. else
  211. return
  212. fi
  213. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  214. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  215. }
  216. # Returns the value of the first option matching option_glob.
  217. # Valid values for option_glob are option names like '--log-level' and
  218. # globs like '--log-level|-l'
  219. # Only positions between the command and the current word are considered.
  220. __docker_value_of_option() {
  221. local option_extglob=$(__docker_to_extglob "$1")
  222. local counter=$((command_pos + 1))
  223. while [ $counter -lt $cword ]; do
  224. case ${words[$counter]} in
  225. $option_extglob )
  226. echo ${words[$counter + 1]}
  227. break
  228. ;;
  229. esac
  230. (( counter++ ))
  231. done
  232. }
  233. # Transforms a multiline list of strings into a single line string
  234. # with the words separated by "|".
  235. # This is used to prepare arguments to __docker_pos_first_nonflag().
  236. __docker_to_alternatives() {
  237. local parts=( $1 )
  238. local IFS='|'
  239. echo "${parts[*]}"
  240. }
  241. # Transforms a multiline list of options into an extglob pattern
  242. # suitable for use in case statements.
  243. __docker_to_extglob() {
  244. local extglob=$( __docker_to_alternatives "$1" )
  245. echo "@($extglob)"
  246. }
  247. # Subcommand processing.
  248. # Locates the first occurrence of any of the subcommands contained in the
  249. # first argument. In case of a match, calls the corresponding completion
  250. # function and returns 0.
  251. # If no match is found, 1 is returned. The calling function can then
  252. # continue processing its completion.
  253. #
  254. # TODO if the preceding command has options that accept arguments and an
  255. # argument is equal ot one of the subcommands, this is falsely detected as
  256. # a match.
  257. __docker_subcommands() {
  258. local subcommands="$1"
  259. local counter=$(($command_pos + 1))
  260. while [ $counter -lt $cword ]; do
  261. case "${words[$counter]}" in
  262. $(__docker_to_extglob "$subcommands") )
  263. subcommand_pos=$counter
  264. local subcommand=${words[$counter]}
  265. local completions_func=_docker_${command}_${subcommand}
  266. declare -F $completions_func >/dev/null && $completions_func
  267. return 0
  268. ;;
  269. esac
  270. (( counter++ ))
  271. done
  272. return 1
  273. }
  274. # suppress trailing whitespace
  275. __docker_nospace() {
  276. # compopt is not available in ancient bash versions
  277. type compopt &>/dev/null && compopt -o nospace
  278. }
  279. __docker_complete_resolved_hostname() {
  280. command -v host >/dev/null 2>&1 || return
  281. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  282. }
  283. __docker_complete_capabilities() {
  284. # The list of capabilities is defined in types.go, ALL was added manually.
  285. COMPREPLY=( $( compgen -W "
  286. ALL
  287. AUDIT_CONTROL
  288. AUDIT_WRITE
  289. AUDIT_READ
  290. BLOCK_SUSPEND
  291. CHOWN
  292. DAC_OVERRIDE
  293. DAC_READ_SEARCH
  294. FOWNER
  295. FSETID
  296. IPC_LOCK
  297. IPC_OWNER
  298. KILL
  299. LEASE
  300. LINUX_IMMUTABLE
  301. MAC_ADMIN
  302. MAC_OVERRIDE
  303. MKNOD
  304. NET_ADMIN
  305. NET_BIND_SERVICE
  306. NET_BROADCAST
  307. NET_RAW
  308. SETFCAP
  309. SETGID
  310. SETPCAP
  311. SETUID
  312. SYS_ADMIN
  313. SYS_BOOT
  314. SYS_CHROOT
  315. SYSLOG
  316. SYS_MODULE
  317. SYS_NICE
  318. SYS_PACCT
  319. SYS_PTRACE
  320. SYS_RAWIO
  321. SYS_RESOURCE
  322. SYS_TIME
  323. SYS_TTY_CONFIG
  324. WAKE_ALARM
  325. " -- "$cur" ) )
  326. }
  327. __docker_complete_detach-keys() {
  328. case "$prev" in
  329. --detach-keys)
  330. case "$cur" in
  331. *,)
  332. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  333. ;;
  334. *)
  335. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  336. ;;
  337. esac
  338. __docker_nospace
  339. return
  340. ;;
  341. esac
  342. return 1
  343. }
  344. __docker_complete_isolation() {
  345. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  346. }
  347. __docker_complete_log_drivers() {
  348. COMPREPLY=( $( compgen -W "
  349. awslogs
  350. etwlogs
  351. fluentd
  352. gcplogs
  353. gelf
  354. journald
  355. json-file
  356. none
  357. splunk
  358. syslog
  359. " -- "$cur" ) )
  360. }
  361. __docker_complete_log_options() {
  362. # see docs/reference/logging/index.md
  363. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  364. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  365. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  366. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  367. local journald_options="env labels tag"
  368. local json_file_options="env labels max-file max-size"
  369. local syslog_options="syslog-address syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify syslog-facility tag"
  370. local splunk_options="env labels splunk-caname splunk-capath splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url tag"
  371. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $json_file_options $syslog_options $splunk_options"
  372. case $(__docker_value_of_option --log-driver) in
  373. '')
  374. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  375. ;;
  376. awslogs)
  377. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  378. ;;
  379. fluentd)
  380. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  381. ;;
  382. gcplogs)
  383. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  384. ;;
  385. gelf)
  386. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  387. ;;
  388. journald)
  389. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  390. ;;
  391. json-file)
  392. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  393. ;;
  394. syslog)
  395. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  396. ;;
  397. splunk)
  398. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  399. ;;
  400. *)
  401. return
  402. ;;
  403. esac
  404. __docker_nospace
  405. }
  406. __docker_complete_log_driver_options() {
  407. local key=$(__docker_map_key_of_current_option '--log-opt')
  408. case "$key" in
  409. fluentd-async-connect)
  410. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  411. return
  412. ;;
  413. gelf-address)
  414. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  415. __docker_nospace
  416. return
  417. ;;
  418. gelf-compression-level)
  419. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  420. return
  421. ;;
  422. gelf-compression-type)
  423. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  424. return
  425. ;;
  426. syslog-address)
  427. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  428. __docker_nospace
  429. __ltrim_colon_completions "${cur}"
  430. return
  431. ;;
  432. syslog-facility)
  433. COMPREPLY=( $( compgen -W "
  434. auth
  435. authpriv
  436. cron
  437. daemon
  438. ftp
  439. kern
  440. local0
  441. local1
  442. local2
  443. local3
  444. local4
  445. local5
  446. local6
  447. local7
  448. lpr
  449. mail
  450. news
  451. syslog
  452. user
  453. uucp
  454. " -- "${cur##*=}" ) )
  455. return
  456. ;;
  457. syslog-format)
  458. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  459. return
  460. ;;
  461. syslog-tls-@(ca-cert|cert|key))
  462. _filedir
  463. return
  464. ;;
  465. syslog-tls-skip-verify)
  466. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  467. return
  468. ;;
  469. splunk-url)
  470. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  471. __docker_nospace
  472. __ltrim_colon_completions "${cur}"
  473. return
  474. ;;
  475. splunk-insecureskipverify)
  476. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  477. return
  478. ;;
  479. esac
  480. return 1
  481. }
  482. __docker_complete_log_levels() {
  483. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  484. }
  485. __docker_complete_restart() {
  486. case "$prev" in
  487. --restart)
  488. case "$cur" in
  489. on-failure:*)
  490. ;;
  491. *)
  492. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  493. ;;
  494. esac
  495. return
  496. ;;
  497. esac
  498. return 1
  499. }
  500. # a selection of the available signals that is most likely of interest in the
  501. # context of docker containers.
  502. __docker_complete_signals() {
  503. local signals=(
  504. SIGCONT
  505. SIGHUP
  506. SIGINT
  507. SIGKILL
  508. SIGQUIT
  509. SIGSTOP
  510. SIGTERM
  511. SIGUSR1
  512. SIGUSR2
  513. )
  514. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  515. }
  516. __docker_complete_user_group() {
  517. if [[ $cur == *:* ]] ; then
  518. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  519. else
  520. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  521. __docker_nospace
  522. fi
  523. }
  524. # global options that may appear after the docker command
  525. _docker_docker() {
  526. local boolean_options="
  527. $global_boolean_options
  528. --help
  529. --version -v
  530. "
  531. case "$prev" in
  532. --config)
  533. _filedir -d
  534. return
  535. ;;
  536. --log-level|-l)
  537. __docker_complete_log_levels
  538. return
  539. ;;
  540. $(__docker_to_extglob "$global_options_with_args") )
  541. return
  542. ;;
  543. esac
  544. case "$cur" in
  545. -*)
  546. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  547. ;;
  548. *)
  549. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  550. if [ $cword -eq $counter ]; then
  551. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  552. fi
  553. ;;
  554. esac
  555. }
  556. _docker_attach() {
  557. __docker_complete_detach-keys && return
  558. case "$cur" in
  559. -*)
  560. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  561. ;;
  562. *)
  563. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  564. if [ $cword -eq $counter ]; then
  565. __docker_complete_containers_running
  566. fi
  567. ;;
  568. esac
  569. }
  570. _docker_build() {
  571. local options_with_args="
  572. --build-arg
  573. --cgroup-parent
  574. --cpuset-cpus
  575. --cpuset-mems
  576. --cpu-shares
  577. --cpu-period
  578. --cpu-quota
  579. --file -f
  580. --isolation
  581. --label
  582. --memory -m
  583. --memory-swap
  584. --shm-size
  585. --tag -t
  586. --ulimit
  587. "
  588. local boolean_options="
  589. --disable-content-trust=false
  590. --force-rm
  591. --help
  592. --no-cache
  593. --pull
  594. --quiet -q
  595. --rm
  596. "
  597. local all_options="$options_with_args $boolean_options"
  598. case "$prev" in
  599. --build-arg)
  600. COMPREPLY=( $( compgen -e -- "$cur" ) )
  601. __docker_nospace
  602. return
  603. ;;
  604. --file|-f)
  605. _filedir
  606. return
  607. ;;
  608. --isolation)
  609. __docker_complete_isolation
  610. return
  611. ;;
  612. --tag|-t)
  613. __docker_complete_image_repos_and_tags
  614. return
  615. ;;
  616. $(__docker_to_extglob "$options_with_args") )
  617. return
  618. ;;
  619. esac
  620. case "$cur" in
  621. -*)
  622. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  623. ;;
  624. *)
  625. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  626. if [ $cword -eq $counter ]; then
  627. _filedir -d
  628. fi
  629. ;;
  630. esac
  631. }
  632. _docker_commit() {
  633. case "$prev" in
  634. --author|-a|--change|-c|--message|-m)
  635. return
  636. ;;
  637. esac
  638. case "$cur" in
  639. -*)
  640. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  641. ;;
  642. *)
  643. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  644. if [ $cword -eq $counter ]; then
  645. __docker_complete_containers_all
  646. return
  647. fi
  648. (( counter++ ))
  649. if [ $cword -eq $counter ]; then
  650. __docker_complete_image_repos_and_tags
  651. return
  652. fi
  653. ;;
  654. esac
  655. }
  656. _docker_cp() {
  657. case "$cur" in
  658. -*)
  659. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  660. ;;
  661. *)
  662. local counter=$(__docker_pos_first_nonflag)
  663. if [ $cword -eq $counter ]; then
  664. case "$cur" in
  665. *:)
  666. return
  667. ;;
  668. *)
  669. # combined container and filename completion
  670. _filedir
  671. local files=( ${COMPREPLY[@]} )
  672. __docker_complete_containers_all
  673. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  674. local containers=( ${COMPREPLY[@]} )
  675. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  676. if [[ "$COMPREPLY" == *: ]]; then
  677. __docker_nospace
  678. fi
  679. return
  680. ;;
  681. esac
  682. fi
  683. (( counter++ ))
  684. if [ $cword -eq $counter ]; then
  685. if [ -e "$prev" ]; then
  686. __docker_complete_containers_all
  687. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  688. __docker_nospace
  689. else
  690. _filedir
  691. fi
  692. return
  693. fi
  694. ;;
  695. esac
  696. }
  697. _docker_create() {
  698. _docker_run
  699. }
  700. _docker_daemon() {
  701. local boolean_options="
  702. $global_boolean_options
  703. --disable-legacy-registry
  704. --help
  705. --icc=false
  706. --ip-forward=false
  707. --ip-masq=false
  708. --iptables=false
  709. --ipv6
  710. --raw-logs
  711. --selinux-enabled
  712. --userland-proxy=false
  713. "
  714. local options_with_args="
  715. $global_options_with_args
  716. --api-cors-header
  717. --authorization-plugin
  718. --bip
  719. --bridge -b
  720. --cgroup-parent
  721. --cluster-advertise
  722. --cluster-store
  723. --cluster-store-opt
  724. --containerd
  725. --default-gateway
  726. --default-gateway-v6
  727. --default-ulimit
  728. --dns
  729. --dns-search
  730. --dns-opt
  731. --exec-opt
  732. --exec-root
  733. --fixed-cidr
  734. --fixed-cidr-v6
  735. --graph -g
  736. --group -G
  737. --insecure-registry
  738. --ip
  739. --label
  740. --log-driver
  741. --log-opt
  742. --mtu
  743. --pidfile -p
  744. --registry-mirror
  745. --storage-driver -s
  746. --storage-opt
  747. --userns-remap
  748. "
  749. __docker_complete_log_driver_options && return
  750. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  751. case "$key" in
  752. kv.*file)
  753. cur=${cur##*=}
  754. _filedir
  755. return
  756. ;;
  757. esac
  758. local key=$(__docker_map_key_of_current_option '--storage-opt')
  759. case "$key" in
  760. dm.@(blkdiscard|override_udev_sync_check|use_deferred_@(removal|deletion)))
  761. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  762. return
  763. ;;
  764. dm.fs)
  765. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  766. return
  767. ;;
  768. dm.thinpooldev)
  769. cur=${cur##*=}
  770. _filedir
  771. return
  772. ;;
  773. esac
  774. case "$prev" in
  775. --authorization-plugin)
  776. __docker_complete_plugins Authorization
  777. return
  778. ;;
  779. --cluster-store)
  780. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  781. __docker_nospace
  782. return
  783. ;;
  784. --cluster-store-opt)
  785. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  786. __docker_nospace
  787. return
  788. ;;
  789. --exec-root|--graph|-g)
  790. _filedir -d
  791. return
  792. ;;
  793. --log-driver)
  794. __docker_complete_log_drivers
  795. return
  796. ;;
  797. --containerd|--pidfile|-p|--tlscacert|--tlscert|--tlskey)
  798. _filedir
  799. return
  800. ;;
  801. --storage-driver|-s)
  802. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  803. return
  804. ;;
  805. --storage-opt)
  806. local devicemapper_options="
  807. dm.basesize
  808. dm.blkdiscard
  809. dm.blocksize
  810. dm.fs
  811. dm.loopdatasize
  812. dm.loopmetadatasize
  813. dm.min_free_space
  814. dm.mkfsarg
  815. dm.mountopt
  816. dm.override_udev_sync_check
  817. dm.thinpooldev
  818. dm.use_deferred_deletion
  819. dm.use_deferred_removal
  820. "
  821. local zfs_options="zfs.fsname"
  822. case $(__docker_value_of_option '--storage-driver|-s') in
  823. '')
  824. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  825. ;;
  826. devicemapper)
  827. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  828. ;;
  829. zfs)
  830. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  831. ;;
  832. *)
  833. return
  834. ;;
  835. esac
  836. __docker_nospace
  837. return
  838. ;;
  839. --log-level|-l)
  840. __docker_complete_log_levels
  841. return
  842. ;;
  843. --log-opt)
  844. __docker_complete_log_options
  845. return
  846. ;;
  847. --userns-remap)
  848. __docker_complete_user_group
  849. return
  850. ;;
  851. $(__docker_to_extglob "$options_with_args") )
  852. return
  853. ;;
  854. esac
  855. case "$cur" in
  856. -*)
  857. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  858. ;;
  859. esac
  860. }
  861. _docker_diff() {
  862. case "$cur" in
  863. -*)
  864. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  865. ;;
  866. *)
  867. local counter=$(__docker_pos_first_nonflag)
  868. if [ $cword -eq $counter ]; then
  869. __docker_complete_containers_all
  870. fi
  871. ;;
  872. esac
  873. }
  874. _docker_events() {
  875. local key=$(__docker_map_key_of_current_option '-f|--filter')
  876. case "$key" in
  877. container)
  878. cur="${cur##*=}"
  879. __docker_complete_containers_all
  880. return
  881. ;;
  882. event)
  883. COMPREPLY=( $( compgen -W "
  884. attach
  885. commit
  886. connect
  887. copy
  888. create
  889. delete
  890. destroy
  891. die
  892. disconnect
  893. exec_create
  894. exec_start
  895. export
  896. import
  897. kill
  898. mount
  899. oom
  900. pause
  901. pull
  902. push
  903. rename
  904. resize
  905. restart
  906. start
  907. stop
  908. tag
  909. top
  910. unmount
  911. unpause
  912. untag
  913. update
  914. " -- "${cur##*=}" ) )
  915. return
  916. ;;
  917. image)
  918. cur="${cur##*=}"
  919. __docker_complete_images
  920. return
  921. ;;
  922. network)
  923. cur="${cur##*=}"
  924. __docker_complete_networks
  925. return
  926. ;;
  927. type)
  928. COMPREPLY=( $( compgen -W "container image network volume" -- "${cur##*=}" ) )
  929. return
  930. ;;
  931. volume)
  932. cur="${cur##*=}"
  933. __docker_complete_volumes
  934. return
  935. ;;
  936. esac
  937. case "$prev" in
  938. --filter|-f)
  939. COMPREPLY=( $( compgen -S = -W "container event image label network type volume" -- "$cur" ) )
  940. __docker_nospace
  941. return
  942. ;;
  943. --since|--until)
  944. return
  945. ;;
  946. esac
  947. case "$cur" in
  948. -*)
  949. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  950. ;;
  951. esac
  952. }
  953. _docker_exec() {
  954. __docker_complete_detach-keys && return
  955. case "$prev" in
  956. --user|-u)
  957. __docker_complete_user_group
  958. return
  959. ;;
  960. esac
  961. case "$cur" in
  962. -*)
  963. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  964. ;;
  965. *)
  966. __docker_complete_containers_running
  967. ;;
  968. esac
  969. }
  970. _docker_export() {
  971. case "$cur" in
  972. -*)
  973. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  974. ;;
  975. *)
  976. local counter=$(__docker_pos_first_nonflag)
  977. if [ $cword -eq $counter ]; then
  978. __docker_complete_containers_all
  979. fi
  980. ;;
  981. esac
  982. }
  983. _docker_help() {
  984. local counter=$(__docker_pos_first_nonflag)
  985. if [ $cword -eq $counter ]; then
  986. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  987. fi
  988. }
  989. _docker_history() {
  990. case "$cur" in
  991. -*)
  992. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  993. ;;
  994. *)
  995. local counter=$(__docker_pos_first_nonflag)
  996. if [ $cword -eq $counter ]; then
  997. __docker_complete_images
  998. fi
  999. ;;
  1000. esac
  1001. }
  1002. _docker_images() {
  1003. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1004. case "$key" in
  1005. dangling)
  1006. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1007. return
  1008. ;;
  1009. label)
  1010. return
  1011. ;;
  1012. esac
  1013. case "$prev" in
  1014. --filter|-f)
  1015. COMPREPLY=( $( compgen -S = -W "dangling label" -- "$cur" ) )
  1016. __docker_nospace
  1017. return
  1018. ;;
  1019. --format)
  1020. return
  1021. ;;
  1022. esac
  1023. case "$cur" in
  1024. -*)
  1025. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1026. ;;
  1027. =)
  1028. return
  1029. ;;
  1030. *)
  1031. __docker_complete_image_repos
  1032. ;;
  1033. esac
  1034. }
  1035. _docker_import() {
  1036. case "$prev" in
  1037. --change|-c|--message|-m)
  1038. return
  1039. ;;
  1040. esac
  1041. case "$cur" in
  1042. -*)
  1043. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1044. ;;
  1045. *)
  1046. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1047. if [ $cword -eq $counter ]; then
  1048. return
  1049. fi
  1050. (( counter++ ))
  1051. if [ $cword -eq $counter ]; then
  1052. __docker_complete_image_repos_and_tags
  1053. return
  1054. fi
  1055. ;;
  1056. esac
  1057. }
  1058. _docker_info() {
  1059. case "$cur" in
  1060. -*)
  1061. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1062. ;;
  1063. esac
  1064. }
  1065. _docker_inspect() {
  1066. case "$prev" in
  1067. --format|-f)
  1068. return
  1069. ;;
  1070. --type)
  1071. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  1072. return
  1073. ;;
  1074. esac
  1075. case "$cur" in
  1076. -*)
  1077. COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) )
  1078. ;;
  1079. *)
  1080. case $(__docker_value_of_option --type) in
  1081. '')
  1082. __docker_complete_containers_and_images
  1083. ;;
  1084. container)
  1085. __docker_complete_containers_all
  1086. ;;
  1087. image)
  1088. __docker_complete_images
  1089. ;;
  1090. esac
  1091. esac
  1092. }
  1093. _docker_kill() {
  1094. case "$prev" in
  1095. --signal|-s)
  1096. __docker_complete_signals
  1097. return
  1098. ;;
  1099. esac
  1100. case "$cur" in
  1101. -*)
  1102. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1103. ;;
  1104. *)
  1105. __docker_complete_containers_running
  1106. ;;
  1107. esac
  1108. }
  1109. _docker_load() {
  1110. case "$prev" in
  1111. --input|-i)
  1112. _filedir
  1113. return
  1114. ;;
  1115. esac
  1116. case "$cur" in
  1117. -*)
  1118. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1119. ;;
  1120. esac
  1121. }
  1122. _docker_login() {
  1123. case "$prev" in
  1124. --password|-p|--username|-u)
  1125. return
  1126. ;;
  1127. esac
  1128. case "$cur" in
  1129. -*)
  1130. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  1131. ;;
  1132. esac
  1133. }
  1134. _docker_logout() {
  1135. case "$cur" in
  1136. -*)
  1137. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1138. ;;
  1139. esac
  1140. }
  1141. _docker_logs() {
  1142. case "$prev" in
  1143. --since|--tail)
  1144. return
  1145. ;;
  1146. esac
  1147. case "$cur" in
  1148. -*)
  1149. COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1150. ;;
  1151. *)
  1152. local counter=$(__docker_pos_first_nonflag '--tail')
  1153. if [ $cword -eq $counter ]; then
  1154. __docker_complete_containers_all
  1155. fi
  1156. ;;
  1157. esac
  1158. }
  1159. _docker_network_connect() {
  1160. local options_with_args="
  1161. --alias
  1162. --ip
  1163. --ip6
  1164. --link
  1165. "
  1166. local boolean_options="
  1167. --help
  1168. "
  1169. case "$prev" in
  1170. --link)
  1171. case "$cur" in
  1172. *:*)
  1173. ;;
  1174. *)
  1175. __docker_complete_containers_running
  1176. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1177. __docker_nospace
  1178. ;;
  1179. esac
  1180. return
  1181. ;;
  1182. $(__docker_to_extglob "$options_with_args") )
  1183. return
  1184. ;;
  1185. esac
  1186. case "$cur" in
  1187. -*)
  1188. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1189. ;;
  1190. *)
  1191. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1192. if [ $cword -eq $counter ]; then
  1193. __docker_complete_networks
  1194. elif [ $cword -eq $(($counter + 1)) ]; then
  1195. __docker_complete_containers_all
  1196. fi
  1197. ;;
  1198. esac
  1199. }
  1200. _docker_network_create() {
  1201. case "$prev" in
  1202. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  1203. return
  1204. ;;
  1205. --ipam-driver)
  1206. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  1207. return
  1208. ;;
  1209. --driver|-d)
  1210. local plugins=" $(__docker_plugins Network) "
  1211. # remove drivers that allow one instance only
  1212. plugins=${plugins/ host / }
  1213. plugins=${plugins/ null / }
  1214. COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
  1215. return
  1216. ;;
  1217. --label)
  1218. return
  1219. ;;
  1220. esac
  1221. case "$cur" in
  1222. -*)
  1223. COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  1224. ;;
  1225. esac
  1226. }
  1227. _docker_network_disconnect() {
  1228. case "$cur" in
  1229. -*)
  1230. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1231. ;;
  1232. *)
  1233. local counter=$(__docker_pos_first_nonflag)
  1234. if [ $cword -eq $counter ]; then
  1235. __docker_complete_networks
  1236. elif [ $cword -eq $(($counter + 1)) ]; then
  1237. __docker_complete_containers_in_network "$prev"
  1238. fi
  1239. ;;
  1240. esac
  1241. }
  1242. _docker_network_inspect() {
  1243. case "$prev" in
  1244. --format|-f)
  1245. return
  1246. ;;
  1247. esac
  1248. case "$cur" in
  1249. -*)
  1250. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1251. ;;
  1252. *)
  1253. __docker_complete_networks
  1254. esac
  1255. }
  1256. _docker_network_ls() {
  1257. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1258. case "$key" in
  1259. driver)
  1260. local plugins=" $(__docker_plugins Network) "
  1261. COMPREPLY=( $(compgen -W "$plugins" -- "${cur##*=}") )
  1262. return
  1263. ;;
  1264. id)
  1265. cur="${cur##*=}"
  1266. __docker_complete_network_ids
  1267. return
  1268. ;;
  1269. name)
  1270. cur="${cur##*=}"
  1271. __docker_complete_network_names
  1272. return
  1273. ;;
  1274. type)
  1275. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  1276. return
  1277. ;;
  1278. esac
  1279. case "$prev" in
  1280. --filter|-f)
  1281. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  1282. __docker_nospace
  1283. return
  1284. ;;
  1285. esac
  1286. case "$cur" in
  1287. -*)
  1288. COMPREPLY=( $( compgen -W "--filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  1289. ;;
  1290. esac
  1291. }
  1292. _docker_network_rm() {
  1293. case "$cur" in
  1294. -*)
  1295. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1296. ;;
  1297. *)
  1298. __docker_complete_networks type=custom
  1299. esac
  1300. }
  1301. _docker_network() {
  1302. local subcommands="
  1303. connect
  1304. create
  1305. disconnect
  1306. inspect
  1307. ls
  1308. rm
  1309. "
  1310. __docker_subcommands "$subcommands" && return
  1311. case "$cur" in
  1312. -*)
  1313. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1314. ;;
  1315. *)
  1316. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1317. ;;
  1318. esac
  1319. }
  1320. _docker_pause() {
  1321. case "$cur" in
  1322. -*)
  1323. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1324. ;;
  1325. *)
  1326. local counter=$(__docker_pos_first_nonflag)
  1327. if [ $cword -eq $counter ]; then
  1328. __docker_complete_containers_pauseable
  1329. fi
  1330. ;;
  1331. esac
  1332. }
  1333. _docker_port() {
  1334. case "$cur" in
  1335. -*)
  1336. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1337. ;;
  1338. *)
  1339. local counter=$(__docker_pos_first_nonflag)
  1340. if [ $cword -eq $counter ]; then
  1341. __docker_complete_containers_all
  1342. fi
  1343. ;;
  1344. esac
  1345. }
  1346. _docker_ps() {
  1347. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1348. case "$key" in
  1349. ancestor)
  1350. cur="${cur##*=}"
  1351. __docker_complete_images
  1352. return
  1353. ;;
  1354. id)
  1355. cur="${cur##*=}"
  1356. __docker_complete_container_ids
  1357. return
  1358. ;;
  1359. name)
  1360. cur="${cur##*=}"
  1361. __docker_complete_container_names
  1362. return
  1363. ;;
  1364. status)
  1365. COMPREPLY=( $( compgen -W "created dead exited paused restarting running" -- "${cur##*=}" ) )
  1366. return
  1367. ;;
  1368. volume)
  1369. cur="${cur##*=}"
  1370. __docker_complete_volumes
  1371. return
  1372. ;;
  1373. esac
  1374. case "$prev" in
  1375. --before|--since)
  1376. __docker_complete_containers_all
  1377. ;;
  1378. --filter|-f)
  1379. COMPREPLY=( $( compgen -S = -W "ancestor exited id label name status volume" -- "$cur" ) )
  1380. __docker_nospace
  1381. return
  1382. ;;
  1383. --format|-n)
  1384. return
  1385. ;;
  1386. esac
  1387. case "$cur" in
  1388. -*)
  1389. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  1390. ;;
  1391. esac
  1392. }
  1393. _docker_pull() {
  1394. case "$cur" in
  1395. -*)
  1396. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  1397. ;;
  1398. *)
  1399. local counter=$(__docker_pos_first_nonflag)
  1400. if [ $cword -eq $counter ]; then
  1401. for arg in "${COMP_WORDS[@]}"; do
  1402. case "$arg" in
  1403. --all-tags|-a)
  1404. __docker_complete_image_repos
  1405. return
  1406. ;;
  1407. esac
  1408. done
  1409. __docker_complete_image_repos_and_tags
  1410. fi
  1411. ;;
  1412. esac
  1413. }
  1414. _docker_push() {
  1415. case "$cur" in
  1416. -*)
  1417. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  1418. ;;
  1419. *)
  1420. local counter=$(__docker_pos_first_nonflag)
  1421. if [ $cword -eq $counter ]; then
  1422. __docker_complete_image_repos_and_tags
  1423. fi
  1424. ;;
  1425. esac
  1426. }
  1427. _docker_rename() {
  1428. case "$cur" in
  1429. -*)
  1430. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1431. ;;
  1432. *)
  1433. local counter=$(__docker_pos_first_nonflag)
  1434. if [ $cword -eq $counter ]; then
  1435. __docker_complete_containers_all
  1436. fi
  1437. ;;
  1438. esac
  1439. }
  1440. _docker_restart() {
  1441. case "$prev" in
  1442. --time|-t)
  1443. return
  1444. ;;
  1445. esac
  1446. case "$cur" in
  1447. -*)
  1448. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1449. ;;
  1450. *)
  1451. __docker_complete_containers_all
  1452. ;;
  1453. esac
  1454. }
  1455. _docker_rm() {
  1456. case "$cur" in
  1457. -*)
  1458. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1459. ;;
  1460. *)
  1461. for arg in "${COMP_WORDS[@]}"; do
  1462. case "$arg" in
  1463. --force|-f)
  1464. __docker_complete_containers_all
  1465. return
  1466. ;;
  1467. esac
  1468. done
  1469. __docker_complete_containers_stopped
  1470. ;;
  1471. esac
  1472. }
  1473. _docker_rmi() {
  1474. case "$cur" in
  1475. -*)
  1476. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  1477. ;;
  1478. *)
  1479. __docker_complete_images
  1480. ;;
  1481. esac
  1482. }
  1483. _docker_run() {
  1484. local options_with_args="
  1485. --add-host
  1486. --attach -a
  1487. --blkio-weight
  1488. --blkio-weight-device
  1489. --cap-add
  1490. --cap-drop
  1491. --cgroup-parent
  1492. --cidfile
  1493. --cpu-period
  1494. --cpu-quota
  1495. --cpuset-cpus
  1496. --cpuset-mems
  1497. --cpu-shares
  1498. --device
  1499. --device-read-bps
  1500. --device-read-iops
  1501. --device-write-bps
  1502. --device-write-iops
  1503. --dns
  1504. --dns-opt
  1505. --dns-search
  1506. --entrypoint
  1507. --env -e
  1508. --env-file
  1509. --expose
  1510. --group-add
  1511. --hostname -h
  1512. --ip
  1513. --ip6
  1514. --ipc
  1515. --isolation
  1516. --kernel-memory
  1517. --label-file
  1518. --label -l
  1519. --link
  1520. --log-driver
  1521. --log-opt
  1522. --mac-address
  1523. --memory -m
  1524. --memory-swap
  1525. --memory-swappiness
  1526. --memory-reservation
  1527. --name
  1528. --net
  1529. --net-alias
  1530. --oom-score-adj
  1531. --pid
  1532. --pids-limit
  1533. --publish -p
  1534. --restart
  1535. --security-opt
  1536. --shm-size
  1537. --stop-signal
  1538. --tmpfs
  1539. --sysctl
  1540. --ulimit
  1541. --user -u
  1542. --userns
  1543. --uts
  1544. --volume-driver
  1545. --volumes-from
  1546. --volume -v
  1547. --workdir -w
  1548. "
  1549. local boolean_options="
  1550. --disable-content-trust=false
  1551. --help
  1552. --interactive -i
  1553. --oom-kill-disable
  1554. --privileged
  1555. --publish-all -P
  1556. --read-only
  1557. --tty -t
  1558. "
  1559. if [ "$command" = "run" ] ; then
  1560. options_with_args="$options_with_args
  1561. --detach-keys
  1562. "
  1563. boolean_options="$boolean_options
  1564. --detach -d
  1565. --rm
  1566. --sig-proxy=false
  1567. "
  1568. __docker_complete_detach-keys && return
  1569. fi
  1570. local all_options="$options_with_args $boolean_options"
  1571. __docker_complete_log_driver_options && return
  1572. __docker_complete_restart && return
  1573. local key=$(__docker_map_key_of_current_option '--security-opt')
  1574. case "$key" in
  1575. label)
  1576. [[ $cur == *: ]] && return
  1577. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1578. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1579. __docker_nospace
  1580. fi
  1581. return
  1582. ;;
  1583. seccomp)
  1584. local cur=${cur##*=}
  1585. _filedir
  1586. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1587. return
  1588. ;;
  1589. esac
  1590. case "$prev" in
  1591. --add-host)
  1592. case "$cur" in
  1593. *:)
  1594. __docker_complete_resolved_hostname
  1595. return
  1596. ;;
  1597. esac
  1598. ;;
  1599. --attach|-a)
  1600. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1601. return
  1602. ;;
  1603. --cap-add|--cap-drop)
  1604. __docker_complete_capabilities
  1605. return
  1606. ;;
  1607. --cidfile|--env-file|--label-file)
  1608. _filedir
  1609. return
  1610. ;;
  1611. --device|--tmpfs|--volume|-v)
  1612. case "$cur" in
  1613. *:*)
  1614. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1615. ;;
  1616. '')
  1617. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1618. __docker_nospace
  1619. ;;
  1620. /*)
  1621. _filedir
  1622. __docker_nospace
  1623. ;;
  1624. esac
  1625. return
  1626. ;;
  1627. --env|-e)
  1628. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1629. __docker_nospace
  1630. return
  1631. ;;
  1632. --ipc)
  1633. case "$cur" in
  1634. *:*)
  1635. cur="${cur#*:}"
  1636. __docker_complete_containers_running
  1637. ;;
  1638. *)
  1639. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1640. if [ "$COMPREPLY" = "container:" ]; then
  1641. __docker_nospace
  1642. fi
  1643. ;;
  1644. esac
  1645. return
  1646. ;;
  1647. --isolation)
  1648. __docker_complete_isolation
  1649. return
  1650. ;;
  1651. --link)
  1652. case "$cur" in
  1653. *:*)
  1654. ;;
  1655. *)
  1656. __docker_complete_containers_running
  1657. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1658. __docker_nospace
  1659. ;;
  1660. esac
  1661. return
  1662. ;;
  1663. --log-driver)
  1664. __docker_complete_log_drivers
  1665. return
  1666. ;;
  1667. --log-opt)
  1668. __docker_complete_log_options
  1669. return
  1670. ;;
  1671. --net)
  1672. case "$cur" in
  1673. container:*)
  1674. local cur=${cur#*:}
  1675. __docker_complete_containers_all
  1676. ;;
  1677. *)
  1678. COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
  1679. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1680. __docker_nospace
  1681. fi
  1682. ;;
  1683. esac
  1684. return
  1685. ;;
  1686. --security-opt)
  1687. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1688. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1689. __docker_nospace
  1690. fi
  1691. return
  1692. ;;
  1693. --user|-u)
  1694. __docker_complete_user_group
  1695. return
  1696. ;;
  1697. --userns)
  1698. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1699. return
  1700. ;;
  1701. --volume-driver)
  1702. __docker_complete_plugins Volume
  1703. return
  1704. ;;
  1705. --volumes-from)
  1706. __docker_complete_containers_all
  1707. return
  1708. ;;
  1709. $(__docker_to_extglob "$options_with_args") )
  1710. return
  1711. ;;
  1712. esac
  1713. case "$cur" in
  1714. -*)
  1715. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1716. ;;
  1717. *)
  1718. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1719. if [ $cword -eq $counter ]; then
  1720. __docker_complete_images
  1721. fi
  1722. ;;
  1723. esac
  1724. }
  1725. _docker_save() {
  1726. case "$prev" in
  1727. --output|-o)
  1728. _filedir
  1729. return
  1730. ;;
  1731. esac
  1732. case "$cur" in
  1733. -*)
  1734. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1735. ;;
  1736. *)
  1737. __docker_complete_images
  1738. ;;
  1739. esac
  1740. }
  1741. _docker_search() {
  1742. case "$prev" in
  1743. --stars|-s)
  1744. return
  1745. ;;
  1746. esac
  1747. case "$cur" in
  1748. -*)
  1749. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  1750. ;;
  1751. esac
  1752. }
  1753. _docker_start() {
  1754. __docker_complete_detach-keys && return
  1755. case "$cur" in
  1756. -*)
  1757. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1758. ;;
  1759. *)
  1760. __docker_complete_containers_stopped
  1761. ;;
  1762. esac
  1763. }
  1764. _docker_stats() {
  1765. case "$cur" in
  1766. -*)
  1767. COMPREPLY=( $( compgen -W "--all -a --help --no-stream" -- "$cur" ) )
  1768. ;;
  1769. *)
  1770. __docker_complete_containers_running
  1771. ;;
  1772. esac
  1773. }
  1774. _docker_stop() {
  1775. case "$prev" in
  1776. --time|-t)
  1777. return
  1778. ;;
  1779. esac
  1780. case "$cur" in
  1781. -*)
  1782. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1783. ;;
  1784. *)
  1785. __docker_complete_containers_running
  1786. ;;
  1787. esac
  1788. }
  1789. _docker_tag() {
  1790. case "$cur" in
  1791. -*)
  1792. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1793. ;;
  1794. *)
  1795. local counter=$(__docker_pos_first_nonflag)
  1796. if [ $cword -eq $counter ]; then
  1797. __docker_complete_image_repos_and_tags
  1798. return
  1799. fi
  1800. (( counter++ ))
  1801. if [ $cword -eq $counter ]; then
  1802. __docker_complete_image_repos_and_tags
  1803. return
  1804. fi
  1805. ;;
  1806. esac
  1807. }
  1808. _docker_unpause() {
  1809. case "$cur" in
  1810. -*)
  1811. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1812. ;;
  1813. *)
  1814. local counter=$(__docker_pos_first_nonflag)
  1815. if [ $cword -eq $counter ]; then
  1816. __docker_complete_containers_unpauseable
  1817. fi
  1818. ;;
  1819. esac
  1820. }
  1821. _docker_update() {
  1822. local options_with_args="
  1823. --blkio-weight
  1824. --cpu-period
  1825. --cpu-quota
  1826. --cpuset-cpus
  1827. --cpuset-mems
  1828. --cpu-shares
  1829. --kernel-memory
  1830. --memory -m
  1831. --memory-reservation
  1832. --memory-swap
  1833. --restart
  1834. "
  1835. local boolean_options="
  1836. --help
  1837. "
  1838. local all_options="$options_with_args $boolean_options"
  1839. __docker_complete_restart && return
  1840. case "$prev" in
  1841. $(__docker_to_extglob "$options_with_args") )
  1842. return
  1843. ;;
  1844. esac
  1845. case "$cur" in
  1846. -*)
  1847. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1848. ;;
  1849. *)
  1850. __docker_complete_containers_all
  1851. ;;
  1852. esac
  1853. }
  1854. _docker_top() {
  1855. case "$cur" in
  1856. -*)
  1857. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1858. ;;
  1859. *)
  1860. local counter=$(__docker_pos_first_nonflag)
  1861. if [ $cword -eq $counter ]; then
  1862. __docker_complete_containers_running
  1863. fi
  1864. ;;
  1865. esac
  1866. }
  1867. _docker_version() {
  1868. case "$cur" in
  1869. -*)
  1870. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1871. ;;
  1872. esac
  1873. }
  1874. _docker_volume_create() {
  1875. case "$prev" in
  1876. --driver|-d)
  1877. __docker_complete_plugins Volume
  1878. return
  1879. ;;
  1880. --label|--name|--opt|-o)
  1881. return
  1882. ;;
  1883. esac
  1884. case "$cur" in
  1885. -*)
  1886. COMPREPLY=( $( compgen -W "--driver -d --help --label --name --opt -o" -- "$cur" ) )
  1887. ;;
  1888. esac
  1889. }
  1890. _docker_volume_inspect() {
  1891. case "$prev" in
  1892. --format|-f)
  1893. return
  1894. ;;
  1895. esac
  1896. case "$cur" in
  1897. -*)
  1898. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  1899. ;;
  1900. *)
  1901. __docker_complete_volumes
  1902. ;;
  1903. esac
  1904. }
  1905. _docker_volume_ls() {
  1906. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1907. case "$key" in
  1908. dangling)
  1909. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1910. return
  1911. ;;
  1912. driver)
  1913. cur=${cur##*=}
  1914. __docker_complete_plugins Volume
  1915. return
  1916. ;;
  1917. name)
  1918. cur=${cur##*=}
  1919. __docker_complete_volumes
  1920. return
  1921. ;;
  1922. esac
  1923. case "$prev" in
  1924. --filter|-f)
  1925. COMPREPLY=( $( compgen -S = -W "dangling driver name" -- "$cur" ) )
  1926. __docker_nospace
  1927. return
  1928. ;;
  1929. esac
  1930. case "$cur" in
  1931. -*)
  1932. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  1933. ;;
  1934. esac
  1935. }
  1936. _docker_volume_rm() {
  1937. case "$cur" in
  1938. -*)
  1939. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1940. ;;
  1941. *)
  1942. __docker_complete_volumes
  1943. ;;
  1944. esac
  1945. }
  1946. _docker_volume() {
  1947. local subcommands="
  1948. create
  1949. inspect
  1950. ls
  1951. rm
  1952. "
  1953. __docker_subcommands "$subcommands" && return
  1954. case "$cur" in
  1955. -*)
  1956. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1957. ;;
  1958. *)
  1959. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1960. ;;
  1961. esac
  1962. }
  1963. _docker_wait() {
  1964. case "$cur" in
  1965. -*)
  1966. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1967. ;;
  1968. *)
  1969. __docker_complete_containers_all
  1970. ;;
  1971. esac
  1972. }
  1973. _docker() {
  1974. local previous_extglob_setting=$(shopt -p extglob)
  1975. shopt -s extglob
  1976. local commands=(
  1977. attach
  1978. build
  1979. commit
  1980. cp
  1981. create
  1982. daemon
  1983. diff
  1984. events
  1985. exec
  1986. export
  1987. history
  1988. images
  1989. import
  1990. info
  1991. inspect
  1992. kill
  1993. load
  1994. login
  1995. logout
  1996. logs
  1997. network
  1998. pause
  1999. port
  2000. ps
  2001. pull
  2002. push
  2003. rename
  2004. restart
  2005. rm
  2006. rmi
  2007. run
  2008. save
  2009. search
  2010. start
  2011. stats
  2012. stop
  2013. tag
  2014. top
  2015. unpause
  2016. update
  2017. version
  2018. volume
  2019. wait
  2020. )
  2021. # These options are valid as global options for all client commands
  2022. # and valid as command options for `docker daemon`
  2023. local global_boolean_options="
  2024. --debug -D
  2025. --tls
  2026. --tlsverify
  2027. "
  2028. local global_options_with_args="
  2029. --config
  2030. --host -H
  2031. --log-level -l
  2032. --tlscacert
  2033. --tlscert
  2034. --tlskey
  2035. "
  2036. local host config
  2037. COMPREPLY=()
  2038. local cur prev words cword
  2039. _get_comp_words_by_ref -n : cur prev words cword
  2040. local command='docker' command_pos=0 subcommand_pos
  2041. local counter=1
  2042. while [ $counter -lt $cword ]; do
  2043. case "${words[$counter]}" in
  2044. # save host so that completion can use custom daemon
  2045. --host|-H)
  2046. (( counter++ ))
  2047. host="${words[$counter]}"
  2048. ;;
  2049. # save config so that completion can use custom configuration directories
  2050. --config)
  2051. (( counter++ ))
  2052. config="${words[$counter]}"
  2053. ;;
  2054. $(__docker_to_extglob "$global_options_with_args") )
  2055. (( counter++ ))
  2056. ;;
  2057. -*)
  2058. ;;
  2059. =)
  2060. (( counter++ ))
  2061. ;;
  2062. *)
  2063. command="${words[$counter]}"
  2064. command_pos=$counter
  2065. break
  2066. ;;
  2067. esac
  2068. (( counter++ ))
  2069. done
  2070. local completions_func=_docker_${command}
  2071. declare -F $completions_func >/dev/null && $completions_func
  2072. eval "$previous_extglob_setting"
  2073. return 0
  2074. }
  2075. eval "$__docker_previous_extglob_setting"
  2076. unset __docker_previous_extglob_setting
  2077. complete -F _docker docker