docker 44 KB

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