docker 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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. # Note:
  19. # Currently, the completions will not work if the docker daemon is not
  20. # bound to the default communication port/socket
  21. # If the docker daemon is using a unix socket for communication your user
  22. # must have access to the socket for the completions to function correctly
  23. #
  24. # Note for developers:
  25. # Please arrange options sorted alphabetically by long name with the short
  26. # options immediately following their corresponding long form.
  27. # This order should be applied to lists, alternatives and code blocks.
  28. __docker_q() {
  29. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  30. }
  31. __docker_containers_all() {
  32. local IFS=$'\n'
  33. local containers=( $(__docker_q ps -aq --no-trunc) )
  34. if [ "$1" ]; then
  35. containers=( $(__docker_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${containers[@]}") )
  36. fi
  37. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  38. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  39. unset IFS
  40. COMPREPLY=( $(compgen -W "${names[*]} ${containers[*]}" -- "$cur") )
  41. }
  42. __docker_containers_running() {
  43. __docker_containers_all '.State.Running'
  44. }
  45. __docker_containers_stopped() {
  46. __docker_containers_all 'not .State.Running'
  47. }
  48. __docker_containers_pauseable() {
  49. __docker_containers_all 'and .State.Running (not .State.Paused)'
  50. }
  51. __docker_containers_unpauseable() {
  52. __docker_containers_all '.State.Paused'
  53. }
  54. __docker_container_names() {
  55. local containers=( $(__docker_q ps -aq --no-trunc) )
  56. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  57. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  58. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  59. }
  60. __docker_container_ids() {
  61. local containers=( $(__docker_q ps -aq) )
  62. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  63. }
  64. __docker_image_repos() {
  65. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  66. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  67. }
  68. __docker_image_repos_and_tags() {
  69. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  70. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  71. __ltrim_colon_completions "$cur"
  72. }
  73. __docker_image_repos_and_tags_and_ids() {
  74. local images="$(__docker_q images -a --no-trunc | awk 'NR>1 { print $3; if ($1 != "<none>") { print $1; print $1":"$2 } }')"
  75. COMPREPLY=( $(compgen -W "$images" -- "$cur") )
  76. __ltrim_colon_completions "$cur"
  77. }
  78. __docker_containers_and_images() {
  79. __docker_containers_all
  80. local containers=( "${COMPREPLY[@]}" )
  81. __docker_image_repos_and_tags_and_ids
  82. COMPREPLY+=( "${containers[@]}" )
  83. }
  84. # Finds the position of the first word that is neither option nor an option's argument.
  85. # If there are options that require arguments, you should pass a glob describing those
  86. # options, e.g. "--option1|-o|--option2"
  87. # Use this function to restrict completions to exact positions after the argument list.
  88. __docker_pos_first_nonflag() {
  89. local argument_flags=$1
  90. local counter=$((command_pos + 1))
  91. while [ $counter -le $cword ]; do
  92. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  93. (( counter++ ))
  94. # eat "=" in case of --option=arg syntax
  95. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  96. else
  97. case "${words[$counter]}" in
  98. -*)
  99. ;;
  100. *)
  101. break
  102. ;;
  103. esac
  104. fi
  105. # Bash splits words at "=", retaining "=" as a word, examples:
  106. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  107. while [ "${words[$counter + 1]}" = "=" ] ; do
  108. counter=$(( counter + 2))
  109. done
  110. (( counter++ ))
  111. done
  112. echo $counter
  113. }
  114. # Returns the value of the first option matching option_glob.
  115. # Valid values for option_glob are option names like '--log-level' and
  116. # globs like '--log-level|-l'
  117. # Only positions between the command and the current word are considered.
  118. __docker_value_of_option() {
  119. local option_glob=$1
  120. local counter=$((command_pos + 1))
  121. while [ $counter -lt $cword ]; do
  122. case ${words[$counter]} in
  123. @($option_glob) )
  124. echo ${words[$counter + 1]}
  125. break
  126. ;;
  127. esac
  128. (( counter++ ))
  129. done
  130. }
  131. # Transforms a multiline list of strings into a single line string
  132. # with the words separated by "|".
  133. # This is used to prepare arguments to __docker_pos_first_nonflag().
  134. __docker_to_alternatives() {
  135. local parts=( $1 )
  136. local IFS='|'
  137. echo "${parts[*]}"
  138. }
  139. # Transforms a multiline list of options into an extglob pattern
  140. # suitable for use in case statements.
  141. __docker_to_extglob() {
  142. local extglob=$( __docker_to_alternatives "$1" )
  143. echo "@($extglob)"
  144. }
  145. __docker_resolve_hostname() {
  146. command -v host >/dev/null 2>&1 || return
  147. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  148. }
  149. __docker_capabilities() {
  150. # The list of capabilities is defined in types.go, ALL was added manually.
  151. COMPREPLY=( $( compgen -W "
  152. ALL
  153. AUDIT_CONTROL
  154. AUDIT_WRITE
  155. AUDIT_READ
  156. BLOCK_SUSPEND
  157. CHOWN
  158. DAC_OVERRIDE
  159. DAC_READ_SEARCH
  160. FOWNER
  161. FSETID
  162. IPC_LOCK
  163. IPC_OWNER
  164. KILL
  165. LEASE
  166. LINUX_IMMUTABLE
  167. MAC_ADMIN
  168. MAC_OVERRIDE
  169. MKNOD
  170. NET_ADMIN
  171. NET_BIND_SERVICE
  172. NET_BROADCAST
  173. NET_RAW
  174. SETFCAP
  175. SETGID
  176. SETPCAP
  177. SETUID
  178. SYS_ADMIN
  179. SYS_BOOT
  180. SYS_CHROOT
  181. SYSLOG
  182. SYS_MODULE
  183. SYS_NICE
  184. SYS_PACCT
  185. SYS_PTRACE
  186. SYS_RAWIO
  187. SYS_RESOURCE
  188. SYS_TIME
  189. SYS_TTY_CONFIG
  190. WAKE_ALARM
  191. " -- "$cur" ) )
  192. }
  193. __docker_log_drivers() {
  194. COMPREPLY=( $( compgen -W "
  195. fluentd
  196. gelf
  197. journald
  198. json-file
  199. none
  200. syslog
  201. " -- "$cur" ) )
  202. }
  203. __docker_log_driver_options() {
  204. # see docs/reference/logging/index.md
  205. local fluentd_options="fluentd-address fluentd-tag"
  206. local gelf_options="gelf-address gelf-tag"
  207. local json_file_options="max-file max-size"
  208. local syslog_options="syslog-address syslog-facility syslog-tag"
  209. case $(__docker_value_of_option --log-driver) in
  210. '')
  211. COMPREPLY=( $( compgen -W "$fluentd_options $gelf_options $json_file_options $syslog_options" -S = -- "$cur" ) )
  212. ;;
  213. fluentd)
  214. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  215. ;;
  216. gelf)
  217. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  218. ;;
  219. json-file)
  220. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  221. ;;
  222. syslog)
  223. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  224. ;;
  225. *)
  226. return
  227. ;;
  228. esac
  229. compopt -o nospace
  230. }
  231. __docker_complete_log_driver_options() {
  232. # "=" gets parsed to a word and assigned to either $cur or $prev depending on whether
  233. # it is the last character or not. So we search for "xxx=" in the the last two words.
  234. case "${words[$cword-2]}$prev=" in
  235. *gelf-address=*)
  236. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur#=}" ) )
  237. compopt -o nospace
  238. return
  239. ;;
  240. *syslog-address=*)
  241. COMPREPLY=( $( compgen -W "tcp udp unix" -S "://" -- "${cur#=}" ) )
  242. compopt -o nospace
  243. return
  244. ;;
  245. *syslog-facility=*)
  246. COMPREPLY=( $( compgen -W "
  247. auth
  248. authpriv
  249. cron
  250. daemon
  251. ftp
  252. kern
  253. local0
  254. local1
  255. local2
  256. local3
  257. local4
  258. local5
  259. local6
  260. local7
  261. lpr
  262. mail
  263. news
  264. syslog
  265. user
  266. uucp
  267. " -- "${cur#=}" ) )
  268. return
  269. ;;
  270. esac
  271. return 1
  272. }
  273. __docker_log_levels() {
  274. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  275. }
  276. # a selection of the available signals that is most likely of interest in the
  277. # context of docker containers.
  278. __docker_signals() {
  279. local signals=(
  280. SIGCONT
  281. SIGHUP
  282. SIGINT
  283. SIGKILL
  284. SIGQUIT
  285. SIGSTOP
  286. SIGTERM
  287. SIGUSR1
  288. SIGUSR2
  289. )
  290. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  291. }
  292. # global options that may appear after the docker command
  293. _docker_docker() {
  294. local boolean_options="
  295. $global_boolean_options
  296. --help
  297. --version -v
  298. "
  299. case "$prev" in
  300. --config)
  301. _filedir -d
  302. return
  303. ;;
  304. --log-level|-l)
  305. __docker_log_levels
  306. return
  307. ;;
  308. $(__docker_to_extglob "$global_options_with_args") )
  309. return
  310. ;;
  311. esac
  312. case "$cur" in
  313. -*)
  314. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  315. ;;
  316. *)
  317. local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") )
  318. if [ $cword -eq $counter ]; then
  319. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  320. fi
  321. ;;
  322. esac
  323. }
  324. _docker_attach() {
  325. case "$cur" in
  326. -*)
  327. COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) )
  328. ;;
  329. *)
  330. local counter="$(__docker_pos_first_nonflag)"
  331. if [ $cword -eq $counter ]; then
  332. __docker_containers_running
  333. fi
  334. ;;
  335. esac
  336. }
  337. _docker_build() {
  338. case "$prev" in
  339. --cgroup-parent|--cpuset-cpus|--cpuset-mems|--cpu-shares|-c|--cpu-period|--cpu-quota|--memory|-m|--memory-swap)
  340. return
  341. ;;
  342. --file|-f)
  343. _filedir
  344. return
  345. ;;
  346. --tag|-t)
  347. __docker_image_repos_and_tags
  348. return
  349. ;;
  350. esac
  351. case "$cur" in
  352. -*)
  353. COMPREPLY=( $( compgen -W "--cgroup-parent --cpuset-cpus --cpuset-mems --cpu-shares -c --cpu-period --cpu-quota --file -f --force-rm --help --memory -m --memory-swap --no-cache --pull --quiet -q --rm --tag -t --ulimit" -- "$cur" ) )
  354. ;;
  355. *)
  356. local counter="$(__docker_pos_first_nonflag '--cgroup-parent|--cpuset-cpus|--cpuset-mems|--cpu-shares|-c|--cpu-period|--cpu-quota|--file|-f|--memory|-m|--memory-swap|--tag|-t')"
  357. if [ $cword -eq $counter ]; then
  358. _filedir -d
  359. fi
  360. ;;
  361. esac
  362. }
  363. _docker_commit() {
  364. case "$prev" in
  365. --author|-a|--change|-c|--message|-m)
  366. return
  367. ;;
  368. esac
  369. case "$cur" in
  370. -*)
  371. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause -p" -- "$cur" ) )
  372. ;;
  373. *)
  374. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  375. if [ $cword -eq $counter ]; then
  376. __docker_containers_all
  377. return
  378. fi
  379. (( counter++ ))
  380. if [ $cword -eq $counter ]; then
  381. __docker_image_repos_and_tags
  382. return
  383. fi
  384. ;;
  385. esac
  386. }
  387. _docker_cp() {
  388. case "$cur" in
  389. -*)
  390. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  391. ;;
  392. *)
  393. local counter=$(__docker_pos_first_nonflag)
  394. if [ $cword -eq $counter ]; then
  395. case "$cur" in
  396. *:)
  397. return
  398. ;;
  399. *)
  400. __docker_containers_all
  401. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  402. compopt -o nospace
  403. return
  404. ;;
  405. esac
  406. fi
  407. (( counter++ ))
  408. if [ $cword -eq $counter ]; then
  409. _filedir -d
  410. return
  411. fi
  412. ;;
  413. esac
  414. }
  415. _docker_create() {
  416. _docker_run
  417. }
  418. _docker_daemon() {
  419. local boolean_options="
  420. $global_boolean_options
  421. --help
  422. --icc=false
  423. --ip-forward=false
  424. --ip-masq=false
  425. --iptables=false
  426. --ipv6
  427. --selinux-enabled
  428. --userland-proxy=false
  429. "
  430. local options_with_args="
  431. $global_options_with_args
  432. --api-cors-header
  433. --bip
  434. --bridge -b
  435. --default-gateway
  436. --default-gateway-v6
  437. --default-ulimit
  438. --dns
  439. --dns-search
  440. --exec-driver -e
  441. --exec-opt
  442. --exec-root
  443. --fixed-cidr
  444. --fixed-cidr-v6
  445. --graph -g
  446. --group -G
  447. --insecure-registry
  448. --ip
  449. --label
  450. --log-driver
  451. --log-opt
  452. --mtu
  453. --pidfile -p
  454. --registry-mirror
  455. --storage-driver -s
  456. --storage-opt
  457. "
  458. case "$prev" in
  459. --exec-root|--graph|-g)
  460. _filedir -d
  461. return
  462. ;;
  463. --log-driver)
  464. __docker_log_drivers
  465. return
  466. ;;
  467. --pidfile|-p|--tlscacert|--tlscert|--tlskey)
  468. _filedir
  469. return
  470. ;;
  471. --storage-driver|-s)
  472. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  473. return
  474. ;;
  475. --storage-opt)
  476. local devicemapper_options="
  477. dm.basesize
  478. dm.blkdiscard
  479. dm.blocksize
  480. dm.fs
  481. dm.loopdatasize
  482. dm.loopmetadatasize
  483. dm.mkfsarg
  484. dm.mountopt
  485. dm.override_udev_sync_check
  486. dm.thinpooldev
  487. "
  488. local zfs_options="zfs.fsname"
  489. case $(__docker_value_of_option '--storage-driver|-s') in
  490. '')
  491. COMPREPLY=( $( compgen -W "$devicemapper_options $zfs_options" -S = -- "$cur" ) )
  492. ;;
  493. devicemapper)
  494. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  495. ;;
  496. zfs)
  497. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  498. ;;
  499. *)
  500. return
  501. ;;
  502. esac
  503. compopt -o nospace
  504. return
  505. ;;
  506. --log-level|-l)
  507. __docker_log_levels
  508. return
  509. ;;
  510. --log-opt)
  511. __docker_log_driver_options
  512. return
  513. ;;
  514. $(__docker_to_extglob "$options_with_args") )
  515. return
  516. ;;
  517. esac
  518. __docker_complete_log_driver_options && return
  519. # completions for --storage-opt
  520. case "${words[$cword-2]}$prev=" in
  521. *dm.blkdiscard=*)
  522. COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) )
  523. return
  524. ;;
  525. *dm.fs=*)
  526. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur#=}" ) )
  527. return
  528. ;;
  529. *dm.override_udev_sync_check=*)
  530. COMPREPLY=( $( compgen -W "false true" -- "${cur#=}" ) )
  531. return
  532. ;;
  533. *dm.thinpooldev=*)
  534. _filedir
  535. return
  536. ;;
  537. esac
  538. case "$cur" in
  539. -*)
  540. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  541. ;;
  542. esac
  543. }
  544. _docker_diff() {
  545. case "$cur" in
  546. -*)
  547. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  548. ;;
  549. *)
  550. local counter=$(__docker_pos_first_nonflag)
  551. if [ $cword -eq $counter ]; then
  552. __docker_containers_all
  553. fi
  554. ;;
  555. esac
  556. }
  557. _docker_events() {
  558. case "$prev" in
  559. --filter|-f)
  560. COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
  561. compopt -o nospace
  562. return
  563. ;;
  564. --since|--until)
  565. return
  566. ;;
  567. esac
  568. case "${words[$cword-2]}$prev=" in
  569. *container=*)
  570. cur="${cur#=}"
  571. __docker_containers_all
  572. return
  573. ;;
  574. *event=*)
  575. COMPREPLY=( $( compgen -W "
  576. attach
  577. commit
  578. copy
  579. create
  580. delete
  581. destroy
  582. die
  583. exec_create
  584. exec_start
  585. export
  586. import
  587. kill
  588. oom
  589. pause
  590. pull
  591. push
  592. rename
  593. resize
  594. restart
  595. start
  596. stop
  597. tag
  598. top
  599. unpause
  600. untag
  601. " -- "${cur#=}" ) )
  602. return
  603. ;;
  604. *image=*)
  605. cur="${cur#=}"
  606. __docker_image_repos_and_tags_and_ids
  607. return
  608. ;;
  609. esac
  610. case "$cur" in
  611. -*)
  612. COMPREPLY=( $( compgen -W "--filter -f --help --since --until" -- "$cur" ) )
  613. ;;
  614. esac
  615. }
  616. _docker_exec() {
  617. case "$prev" in
  618. --user|-u)
  619. return
  620. ;;
  621. esac
  622. case "$cur" in
  623. -*)
  624. COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  625. ;;
  626. *)
  627. __docker_containers_running
  628. ;;
  629. esac
  630. }
  631. _docker_export() {
  632. case "$cur" in
  633. -*)
  634. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  635. ;;
  636. *)
  637. local counter=$(__docker_pos_first_nonflag)
  638. if [ $cword -eq $counter ]; then
  639. __docker_containers_all
  640. fi
  641. ;;
  642. esac
  643. }
  644. _docker_help() {
  645. local counter=$(__docker_pos_first_nonflag)
  646. if [ $cword -eq $counter ]; then
  647. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  648. fi
  649. }
  650. _docker_history() {
  651. case "$cur" in
  652. -*)
  653. COMPREPLY=( $( compgen -W "--help --no-trunc --quiet -q" -- "$cur" ) )
  654. ;;
  655. *)
  656. local counter=$(__docker_pos_first_nonflag)
  657. if [ $cword -eq $counter ]; then
  658. __docker_image_repos_and_tags_and_ids
  659. fi
  660. ;;
  661. esac
  662. }
  663. _docker_images() {
  664. case "$prev" in
  665. --filter|-f)
  666. COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
  667. if [ "$COMPREPLY" = "label=" ]; then
  668. compopt -o nospace
  669. fi
  670. return
  671. ;;
  672. esac
  673. case "${words[$cword-2]}$prev=" in
  674. *dangling=*)
  675. COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
  676. return
  677. ;;
  678. *label=*)
  679. return
  680. ;;
  681. esac
  682. case "$cur" in
  683. -*)
  684. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
  685. ;;
  686. =)
  687. return
  688. ;;
  689. *)
  690. __docker_image_repos
  691. ;;
  692. esac
  693. }
  694. _docker_import() {
  695. case "$cur" in
  696. -*)
  697. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  698. ;;
  699. *)
  700. local counter=$(__docker_pos_first_nonflag)
  701. if [ $cword -eq $counter ]; then
  702. return
  703. fi
  704. (( counter++ ))
  705. if [ $cword -eq $counter ]; then
  706. __docker_image_repos_and_tags
  707. return
  708. fi
  709. ;;
  710. esac
  711. }
  712. _docker_info() {
  713. case "$cur" in
  714. -*)
  715. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  716. ;;
  717. esac
  718. }
  719. _docker_inspect() {
  720. case "$prev" in
  721. --format|-f)
  722. return
  723. ;;
  724. --type)
  725. COMPREPLY=( $( compgen -W "image container" -- "$cur" ) )
  726. return
  727. ;;
  728. esac
  729. case "$cur" in
  730. -*)
  731. COMPREPLY=( $( compgen -W "--format -f --type --help" -- "$cur" ) )
  732. ;;
  733. *)
  734. case $(__docker_value_of_option --type) in
  735. '')
  736. __docker_containers_and_images
  737. ;;
  738. container)
  739. __docker_containers_all
  740. ;;
  741. image)
  742. __docker_image_repos_and_tags_and_ids
  743. ;;
  744. esac
  745. esac
  746. }
  747. _docker_kill() {
  748. case "$prev" in
  749. --signal|-s)
  750. __docker_signals
  751. return
  752. ;;
  753. esac
  754. case "$cur" in
  755. -*)
  756. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  757. ;;
  758. *)
  759. __docker_containers_running
  760. ;;
  761. esac
  762. }
  763. _docker_load() {
  764. case "$prev" in
  765. --input|-i)
  766. _filedir
  767. return
  768. ;;
  769. esac
  770. case "$cur" in
  771. -*)
  772. COMPREPLY=( $( compgen -W "--help --input -i" -- "$cur" ) )
  773. ;;
  774. esac
  775. }
  776. _docker_login() {
  777. case "$prev" in
  778. --email|-e|--password|-p|--username|-u)
  779. return
  780. ;;
  781. esac
  782. case "$cur" in
  783. -*)
  784. COMPREPLY=( $( compgen -W "--email -e --help --password -p --username -u" -- "$cur" ) )
  785. ;;
  786. esac
  787. }
  788. _docker_logout() {
  789. case "$cur" in
  790. -*)
  791. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  792. ;;
  793. esac
  794. }
  795. _docker_logs() {
  796. case "$prev" in
  797. --since|--tail)
  798. return
  799. ;;
  800. esac
  801. case "$cur" in
  802. -*)
  803. COMPREPLY=( $( compgen -W "--follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  804. ;;
  805. *)
  806. local counter=$(__docker_pos_first_nonflag '--tail')
  807. if [ $cword -eq $counter ]; then
  808. __docker_containers_all
  809. fi
  810. ;;
  811. esac
  812. }
  813. _docker_pause() {
  814. case "$cur" in
  815. -*)
  816. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  817. ;;
  818. *)
  819. local counter=$(__docker_pos_first_nonflag)
  820. if [ $cword -eq $counter ]; then
  821. __docker_containers_pauseable
  822. fi
  823. ;;
  824. esac
  825. }
  826. _docker_port() {
  827. case "$cur" in
  828. -*)
  829. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  830. ;;
  831. *)
  832. local counter=$(__docker_pos_first_nonflag)
  833. if [ $cword -eq $counter ]; then
  834. __docker_containers_all
  835. fi
  836. ;;
  837. esac
  838. }
  839. _docker_ps() {
  840. case "$prev" in
  841. --before|--since)
  842. __docker_containers_all
  843. ;;
  844. --filter|-f)
  845. COMPREPLY=( $( compgen -S = -W "exited id label name status" -- "$cur" ) )
  846. compopt -o nospace
  847. return
  848. ;;
  849. --format|-n)
  850. return
  851. ;;
  852. esac
  853. case "${words[$cword-2]}$prev=" in
  854. *id=*)
  855. cur="${cur#=}"
  856. __docker_container_ids
  857. return
  858. ;;
  859. *name=*)
  860. cur="${cur#=}"
  861. __docker_container_names
  862. return
  863. ;;
  864. *status=*)
  865. COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
  866. return
  867. ;;
  868. esac
  869. case "$cur" in
  870. -*)
  871. COMPREPLY=( $( compgen -W "--all -a --before --filter -f --format --help --latest -l -n --no-trunc --quiet -q --size -s --since" -- "$cur" ) )
  872. ;;
  873. esac
  874. }
  875. _docker_pull() {
  876. case "$cur" in
  877. -*)
  878. COMPREPLY=( $( compgen -W "--all-tags -a --help" -- "$cur" ) )
  879. ;;
  880. *)
  881. local counter=$(__docker_pos_first_nonflag)
  882. if [ $cword -eq $counter ]; then
  883. for arg in "${COMP_WORDS[@]}"; do
  884. case "$arg" in
  885. --all-tags|-a)
  886. __docker_image_repos
  887. return
  888. ;;
  889. esac
  890. done
  891. __docker_image_repos_and_tags
  892. fi
  893. ;;
  894. esac
  895. }
  896. _docker_push() {
  897. case "$cur" in
  898. -*)
  899. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  900. ;;
  901. *)
  902. local counter=$(__docker_pos_first_nonflag)
  903. if [ $cword -eq $counter ]; then
  904. __docker_image_repos_and_tags
  905. fi
  906. ;;
  907. esac
  908. }
  909. _docker_rename() {
  910. case "$cur" in
  911. -*)
  912. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  913. ;;
  914. *)
  915. local counter=$(__docker_pos_first_nonflag)
  916. if [ $cword -eq $counter ]; then
  917. __docker_containers_all
  918. fi
  919. ;;
  920. esac
  921. }
  922. _docker_restart() {
  923. case "$prev" in
  924. --time|-t)
  925. return
  926. ;;
  927. esac
  928. case "$cur" in
  929. -*)
  930. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  931. ;;
  932. *)
  933. __docker_containers_all
  934. ;;
  935. esac
  936. }
  937. _docker_rm() {
  938. case "$cur" in
  939. -*)
  940. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  941. ;;
  942. *)
  943. for arg in "${COMP_WORDS[@]}"; do
  944. case "$arg" in
  945. --force|-f)
  946. __docker_containers_all
  947. return
  948. ;;
  949. esac
  950. done
  951. __docker_containers_stopped
  952. ;;
  953. esac
  954. }
  955. _docker_rmi() {
  956. case "$cur" in
  957. -*)
  958. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  959. ;;
  960. *)
  961. __docker_image_repos_and_tags_and_ids
  962. ;;
  963. esac
  964. }
  965. _docker_run() {
  966. local options_with_args="
  967. --add-host
  968. --attach -a
  969. --blkio-weight
  970. --cap-add
  971. --cap-drop
  972. --cgroup-parent
  973. --cidfile
  974. --cpu-period
  975. --cpu-quota
  976. --cpuset-cpus
  977. --cpuset-mems
  978. --cpu-shares -c
  979. --device
  980. --dns
  981. --dns-search
  982. --entrypoint
  983. --env -e
  984. --env-file
  985. --expose
  986. --group-add
  987. --hostname -h
  988. --ipc
  989. --label-file
  990. --label -l
  991. --link
  992. --log-driver
  993. --log-opt
  994. --lxc-conf
  995. --mac-address
  996. --memory -m
  997. --memory-swap
  998. --memory-swappiness
  999. --name
  1000. --net
  1001. --pid
  1002. --publish -p
  1003. --restart
  1004. --security-opt
  1005. --ulimit
  1006. --user -u
  1007. --uts
  1008. --volumes-from
  1009. --volume -v
  1010. --workdir -w
  1011. "
  1012. local all_options="$options_with_args
  1013. --disable-content-trust=false
  1014. --help
  1015. --interactive -i
  1016. --oom-kill-disable
  1017. --privileged
  1018. --publish-all -P
  1019. --read-only
  1020. --tty -t
  1021. "
  1022. [ "$command" = "run" ] && all_options="$all_options
  1023. --detach -d
  1024. --rm
  1025. --sig-proxy=false
  1026. "
  1027. local options_with_args_glob=$(__docker_to_extglob "$options_with_args")
  1028. case "$prev" in
  1029. --add-host)
  1030. case "$cur" in
  1031. *:)
  1032. __docker_resolve_hostname
  1033. return
  1034. ;;
  1035. esac
  1036. ;;
  1037. --attach|-a)
  1038. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1039. return
  1040. ;;
  1041. --cap-add|--cap-drop)
  1042. __docker_capabilities
  1043. return
  1044. ;;
  1045. --cidfile|--env-file|--label-file)
  1046. _filedir
  1047. return
  1048. ;;
  1049. --device|--volume|-v)
  1050. case "$cur" in
  1051. *:*)
  1052. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1053. ;;
  1054. '')
  1055. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1056. compopt -o nospace
  1057. ;;
  1058. /*)
  1059. _filedir
  1060. compopt -o nospace
  1061. ;;
  1062. esac
  1063. return
  1064. ;;
  1065. --env|-e)
  1066. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1067. compopt -o nospace
  1068. return
  1069. ;;
  1070. --ipc)
  1071. case "$cur" in
  1072. *:*)
  1073. cur="${cur#*:}"
  1074. __docker_containers_running
  1075. ;;
  1076. *)
  1077. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1078. if [ "$COMPREPLY" = "container:" ]; then
  1079. compopt -o nospace
  1080. fi
  1081. ;;
  1082. esac
  1083. return
  1084. ;;
  1085. --link)
  1086. case "$cur" in
  1087. *:*)
  1088. ;;
  1089. *)
  1090. __docker_containers_running
  1091. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1092. compopt -o nospace
  1093. ;;
  1094. esac
  1095. return
  1096. ;;
  1097. --log-driver)
  1098. __docker_log_drivers
  1099. return
  1100. ;;
  1101. --log-opt)
  1102. __docker_log_driver_options
  1103. return
  1104. ;;
  1105. --net)
  1106. case "$cur" in
  1107. container:*)
  1108. local cur=${cur#*:}
  1109. __docker_containers_all
  1110. ;;
  1111. *)
  1112. COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
  1113. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1114. compopt -o nospace
  1115. fi
  1116. ;;
  1117. esac
  1118. return
  1119. ;;
  1120. --restart)
  1121. case "$cur" in
  1122. on-failure:*)
  1123. ;;
  1124. *)
  1125. COMPREPLY=( $( compgen -W "no on-failure on-failure: always" -- "$cur") )
  1126. ;;
  1127. esac
  1128. return
  1129. ;;
  1130. --security-opt)
  1131. case "$cur" in
  1132. label:*:*)
  1133. ;;
  1134. label:*)
  1135. local cur=${cur##*:}
  1136. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "$cur") )
  1137. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1138. compopt -o nospace
  1139. fi
  1140. ;;
  1141. *)
  1142. COMPREPLY=( $( compgen -W "label apparmor" -S ":" -- "$cur") )
  1143. compopt -o nospace
  1144. ;;
  1145. esac
  1146. return
  1147. ;;
  1148. --volumes-from)
  1149. __docker_containers_all
  1150. return
  1151. ;;
  1152. $options_with_args_glob )
  1153. return
  1154. ;;
  1155. esac
  1156. __docker_complete_log_driver_options && return
  1157. case "$cur" in
  1158. -*)
  1159. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1160. ;;
  1161. *)
  1162. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1163. if [ $cword -eq $counter ]; then
  1164. __docker_image_repos_and_tags_and_ids
  1165. fi
  1166. ;;
  1167. esac
  1168. }
  1169. _docker_save() {
  1170. case "$prev" in
  1171. --output|-o)
  1172. _filedir
  1173. return
  1174. ;;
  1175. esac
  1176. case "$cur" in
  1177. -*)
  1178. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  1179. ;;
  1180. *)
  1181. __docker_image_repos_and_tags_and_ids
  1182. ;;
  1183. esac
  1184. }
  1185. _docker_search() {
  1186. case "$prev" in
  1187. --stars|-s)
  1188. return
  1189. ;;
  1190. esac
  1191. case "$cur" in
  1192. -*)
  1193. COMPREPLY=( $( compgen -W "--automated --help --no-trunc --stars -s" -- "$cur" ) )
  1194. ;;
  1195. esac
  1196. }
  1197. _docker_start() {
  1198. case "$cur" in
  1199. -*)
  1200. COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
  1201. ;;
  1202. *)
  1203. __docker_containers_stopped
  1204. ;;
  1205. esac
  1206. }
  1207. _docker_stats() {
  1208. case "$cur" in
  1209. -*)
  1210. COMPREPLY=( $( compgen -W "--no-stream --help" -- "$cur" ) )
  1211. ;;
  1212. *)
  1213. __docker_containers_running
  1214. ;;
  1215. esac
  1216. }
  1217. _docker_stop() {
  1218. case "$prev" in
  1219. --time|-t)
  1220. return
  1221. ;;
  1222. esac
  1223. case "$cur" in
  1224. -*)
  1225. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1226. ;;
  1227. *)
  1228. __docker_containers_running
  1229. ;;
  1230. esac
  1231. }
  1232. _docker_tag() {
  1233. case "$cur" in
  1234. -*)
  1235. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  1236. ;;
  1237. *)
  1238. local counter=$(__docker_pos_first_nonflag)
  1239. if [ $cword -eq $counter ]; then
  1240. __docker_image_repos_and_tags
  1241. return
  1242. fi
  1243. (( counter++ ))
  1244. if [ $cword -eq $counter ]; then
  1245. __docker_image_repos_and_tags
  1246. return
  1247. fi
  1248. ;;
  1249. esac
  1250. }
  1251. _docker_unpause() {
  1252. case "$cur" in
  1253. -*)
  1254. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1255. ;;
  1256. *)
  1257. local counter=$(__docker_pos_first_nonflag)
  1258. if [ $cword -eq $counter ]; then
  1259. __docker_containers_unpauseable
  1260. fi
  1261. ;;
  1262. esac
  1263. }
  1264. _docker_top() {
  1265. case "$cur" in
  1266. -*)
  1267. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1268. ;;
  1269. *)
  1270. local counter=$(__docker_pos_first_nonflag)
  1271. if [ $cword -eq $counter ]; then
  1272. __docker_containers_running
  1273. fi
  1274. ;;
  1275. esac
  1276. }
  1277. _docker_version() {
  1278. case "$cur" in
  1279. -*)
  1280. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1281. ;;
  1282. esac
  1283. }
  1284. _docker_wait() {
  1285. case "$cur" in
  1286. -*)
  1287. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1288. ;;
  1289. *)
  1290. __docker_containers_all
  1291. ;;
  1292. esac
  1293. }
  1294. _docker() {
  1295. local previous_extglob_setting=$(shopt -p extglob)
  1296. shopt -s extglob
  1297. local commands=(
  1298. attach
  1299. build
  1300. commit
  1301. cp
  1302. create
  1303. daemon
  1304. diff
  1305. events
  1306. exec
  1307. export
  1308. history
  1309. images
  1310. import
  1311. info
  1312. inspect
  1313. kill
  1314. load
  1315. login
  1316. logout
  1317. logs
  1318. pause
  1319. port
  1320. ps
  1321. pull
  1322. push
  1323. rename
  1324. restart
  1325. rm
  1326. rmi
  1327. run
  1328. save
  1329. search
  1330. start
  1331. stats
  1332. stop
  1333. tag
  1334. top
  1335. unpause
  1336. version
  1337. wait
  1338. )
  1339. # These options are valid as global options for all client commands
  1340. # and valid as command options for `docker daemon`
  1341. local global_boolean_options="
  1342. --debug -D
  1343. --tls
  1344. --tlsverify
  1345. "
  1346. local global_options_with_args="
  1347. --config
  1348. --host -H
  1349. --log-level -l
  1350. --tlscacert
  1351. --tlscert
  1352. --tlskey
  1353. "
  1354. local host config
  1355. COMPREPLY=()
  1356. local cur prev words cword
  1357. _get_comp_words_by_ref -n : cur prev words cword
  1358. local command='docker' command_pos=0
  1359. local counter=1
  1360. while [ $counter -lt $cword ]; do
  1361. case "${words[$counter]}" in
  1362. # save host so that completion can use custom daemon
  1363. --host|-H)
  1364. (( counter++ ))
  1365. host="${words[$counter]}"
  1366. ;;
  1367. # save config so that completion can use custom configuration directories
  1368. --config)
  1369. (( counter++ ))
  1370. config="${words[$counter]}"
  1371. ;;
  1372. $(__docker_to_extglob "$global_options_with_args") )
  1373. (( counter++ ))
  1374. ;;
  1375. -*)
  1376. ;;
  1377. =)
  1378. (( counter++ ))
  1379. ;;
  1380. *)
  1381. command="${words[$counter]}"
  1382. command_pos=$counter
  1383. break
  1384. ;;
  1385. esac
  1386. (( counter++ ))
  1387. done
  1388. local completions_func=_docker_${command}
  1389. declare -F $completions_func >/dev/null && $completions_func
  1390. eval "$previous_extglob_setting"
  1391. return 0
  1392. }
  1393. complete -F _docker docker