Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

get-docker.sh 21 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
  1. #!/bin/sh
  2. set -e
  3. # Docker Engine for Linux installation script.
  4. #
  5. # This script is intended as a convenient way to configure docker's package
  6. # repositories and to install Docker Engine, This script is not recommended
  7. # for production environments. Before running this script, make yourself familiar
  8. # with potential risks and limitations, and refer to the installation manual
  9. # at https://docs.docker.com/engine/install/ for alternative installation methods.
  10. #
  11. # The script:
  12. #
  13. # - Requires `root` or `sudo` privileges to run.
  14. # - Attempts to detect your Linux distribution and version and configure your
  15. # package management system for you.
  16. # - Doesn't allow you to customize most installation parameters.
  17. # - Installs dependencies and recommendations without asking for confirmation.
  18. # - Installs the latest stable release (by default) of Docker CLI, Docker Engine,
  19. # Docker Buildx, Docker Compose, containerd, and runc. When using this script
  20. # to provision a machine, this may result in unexpected major version upgrades
  21. # of these packages. Always test upgrades in a test environment before
  22. # deploying to your production systems.
  23. # - Isn't designed to upgrade an existing Docker installation. When using the
  24. # script to update an existing installation, dependencies may not be updated
  25. # to the expected version, resulting in outdated versions.
  26. #
  27. # Source code is available at https://github.com/docker/docker-install/
  28. #
  29. # Usage
  30. # ==============================================================================
  31. #
  32. # To install the latest stable versions of Docker CLI, Docker Engine, and their
  33. # dependencies:
  34. #
  35. # 1. download the script
  36. #
  37. # $ curl -fsSL https://get.docker.com -o install-docker.sh
  38. #
  39. # 2. verify the script's content
  40. #
  41. # $ cat install-docker.sh
  42. #
  43. # 3. run the script with --dry-run to verify the steps it executes
  44. #
  45. # $ sh install-docker.sh --dry-run
  46. #
  47. # 4. run the script either as root, or using sudo to perform the installation.
  48. #
  49. # $ sudo sh install-docker.sh
  50. #
  51. # Command-line options
  52. # ==============================================================================
  53. #
  54. # --version <VERSION>
  55. # Use the --version option to install a specific version, for example:
  56. #
  57. # $ sudo sh install-docker.sh --version 23.0
  58. #
  59. # --channel <stable|test>
  60. #
  61. # Use the --channel option to install from an alternative installation channel.
  62. # The following example installs the latest versions from the "test" channel,
  63. # which includes pre-releases (alpha, beta, rc):
  64. #
  65. # $ sudo sh install-docker.sh --channel test
  66. #
  67. # Alternatively, use the script at https://test.docker.com, which uses the test
  68. # channel as default.
  69. #
  70. # --mirror <Aliyun|AzureChinaCloud>
  71. #
  72. # Use the --mirror option to install from a mirror supported by this script.
  73. # Available mirrors are "Aliyun" (https://mirrors.aliyun.com/docker-ce), and
  74. # "AzureChinaCloud" (https://mirror.azure.cn/docker-ce), for example:
  75. #
  76. # $ sudo sh install-docker.sh --mirror AzureChinaCloud
  77. #
  78. # ==============================================================================
  79. # Git commit from https://github.com/docker/docker-install when
  80. # the script was uploaded (Should only be modified by upload job):
  81. SCRIPT_COMMIT_SHA="e5543d473431b782227f8908005543bb4389b8de"
  82. # strip "v" prefix if present
  83. VERSION="${VERSION#v}"
  84. # The channel to install from:
  85. # * stable
  86. # * test
  87. # * edge (deprecated)
  88. # * nightly (deprecated)
  89. DEFAULT_CHANNEL_VALUE="stable"
  90. if [ -z "$CHANNEL" ]; then
  91. CHANNEL=$DEFAULT_CHANNEL_VALUE
  92. fi
  93. DEFAULT_DOWNLOAD_URL="https://download.docker.com"
  94. if [ -z "$DOWNLOAD_URL" ]; then
  95. DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
  96. fi
  97. DEFAULT_REPO_FILE="docker-ce.repo"
  98. if [ -z "$REPO_FILE" ]; then
  99. REPO_FILE="$DEFAULT_REPO_FILE"
  100. fi
  101. mirror=''
  102. DRY_RUN=${DRY_RUN:-}
  103. while [ $# -gt 0 ]; do
  104. case "$1" in
  105. --channel)
  106. CHANNEL="$2"
  107. shift
  108. ;;
  109. --dry-run)
  110. DRY_RUN=1
  111. ;;
  112. --mirror)
  113. mirror="$2"
  114. shift
  115. ;;
  116. --version)
  117. VERSION="${2#v}"
  118. shift
  119. ;;
  120. --*)
  121. echo "Illegal option $1"
  122. ;;
  123. esac
  124. shift $(( $# > 0 ? 1 : 0 ))
  125. done
  126. case "$mirror" in
  127. Aliyun)
  128. DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
  129. ;;
  130. AzureChinaCloud)
  131. DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
  132. ;;
  133. "")
  134. ;;
  135. *)
  136. >&2 echo "unknown mirror '$mirror': use either 'Aliyun', or 'AzureChinaCloud'."
  137. exit 1
  138. ;;
  139. esac
  140. case "$CHANNEL" in
  141. stable|test)
  142. ;;
  143. edge|nightly)
  144. >&2 echo "DEPRECATED: the $CHANNEL channel has been deprecated and is no longer supported by this script."
  145. exit 1
  146. ;;
  147. *)
  148. >&2 echo "unknown CHANNEL '$CHANNEL': use either stable or test."
  149. exit 1
  150. ;;
  151. esac
  152. command_exists() {
  153. command -v "$@" > /dev/null 2>&1
  154. }
  155. # version_gte checks if the version specified in $VERSION is at least the given
  156. # SemVer (Maj.Minor[.Patch]), or CalVer (YY.MM) version.It returns 0 (success)
  157. # if $VERSION is either unset (=latest) or newer or equal than the specified
  158. # version, or returns 1 (fail) otherwise.
  159. #
  160. # examples:
  161. #
  162. # VERSION=23.0
  163. # version_gte 23.0 // 0 (success)
  164. # version_gte 20.10 // 0 (success)
  165. # version_gte 19.03 // 0 (success)
  166. # version_gte 21.10 // 1 (fail)
  167. version_gte() {
  168. if [ -z "$VERSION" ]; then
  169. return 0
  170. fi
  171. eval version_compare "$VERSION" "$1"
  172. }
  173. # version_compare compares two version strings (either SemVer (Major.Minor.Path),
  174. # or CalVer (YY.MM) version strings. It returns 0 (success) if version A is newer
  175. # or equal than version B, or 1 (fail) otherwise. Patch releases and pre-release
  176. # (-alpha/-beta) are not taken into account
  177. #
  178. # examples:
  179. #
  180. # version_compare 23.0.0 20.10 // 0 (success)
  181. # version_compare 23.0 20.10 // 0 (success)
  182. # version_compare 20.10 19.03 // 0 (success)
  183. # version_compare 20.10 20.10 // 0 (success)
  184. # version_compare 19.03 20.10 // 1 (fail)
  185. version_compare() (
  186. set +x
  187. yy_a="$(echo "$1" | cut -d'.' -f1)"
  188. yy_b="$(echo "$2" | cut -d'.' -f1)"
  189. if [ "$yy_a" -lt "$yy_b" ]; then
  190. return 1
  191. fi
  192. if [ "$yy_a" -gt "$yy_b" ]; then
  193. return 0
  194. fi
  195. mm_a="$(echo "$1" | cut -d'.' -f2)"
  196. mm_b="$(echo "$2" | cut -d'.' -f2)"
  197. # trim leading zeros to accommodate CalVer
  198. mm_a="${mm_a#0}"
  199. mm_b="${mm_b#0}"
  200. if [ "${mm_a:-0}" -lt "${mm_b:-0}" ]; then
  201. return 1
  202. fi
  203. return 0
  204. )
  205. is_dry_run() {
  206. if [ -z "$DRY_RUN" ]; then
  207. return 1
  208. else
  209. return 0
  210. fi
  211. }
  212. is_wsl() {
  213. case "$(uname -r)" in
  214. *microsoft* ) true ;; # WSL 2
  215. *Microsoft* ) true ;; # WSL 1
  216. * ) false;;
  217. esac
  218. }
  219. is_darwin() {
  220. case "$(uname -s)" in
  221. *darwin* ) true ;;
  222. *Darwin* ) true ;;
  223. * ) false;;
  224. esac
  225. }
  226. deprecation_notice() {
  227. distro=$1
  228. distro_version=$2
  229. echo
  230. printf "\033[91;1mDEPRECATION WARNING\033[0m\n"
  231. printf " This Linux distribution (\033[1m%s %s\033[0m) reached end-of-life and is no longer supported by this script.\n" "$distro" "$distro_version"
  232. echo " No updates or security fixes will be released for this distribution, and users are recommended"
  233. echo " to upgrade to a currently maintained version of $distro."
  234. echo
  235. printf "Press \033[1mCtrl+C\033[0m now to abort this script, or wait for the installation to continue."
  236. echo
  237. sleep 10
  238. }
  239. get_distribution() {
  240. lsb_dist=""
  241. # Every system that we officially support has /etc/os-release
  242. if [ -r /etc/os-release ]; then
  243. lsb_dist="$(. /etc/os-release && echo "$ID")"
  244. fi
  245. # Returning an empty string here should be alright since the
  246. # case statements don't act unless you provide an actual value
  247. echo "$lsb_dist"
  248. }
  249. echo_docker_as_nonroot() {
  250. if is_dry_run; then
  251. return
  252. fi
  253. if command_exists docker && [ -e /var/run/docker.sock ]; then
  254. (
  255. set -x
  256. $sh_c 'docker version'
  257. ) || true
  258. fi
  259. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
  260. echo
  261. echo "================================================================================"
  262. echo
  263. if version_gte "20.10"; then
  264. echo "To run Docker as a non-privileged user, consider setting up the"
  265. echo "Docker daemon in rootless mode for your user:"
  266. echo
  267. echo " dockerd-rootless-setuptool.sh install"
  268. echo
  269. echo "Visit https://docs.docker.com/go/rootless/ to learn about rootless mode."
  270. echo
  271. fi
  272. echo
  273. echo "To run the Docker daemon as a fully privileged service, but granting non-root"
  274. echo "users access, refer to https://docs.docker.com/go/daemon-access/"
  275. echo
  276. echo "WARNING: Access to the remote API on a privileged Docker daemon is equivalent"
  277. echo " to root access on the host. Refer to the 'Docker daemon attack surface'"
  278. echo " documentation for details: https://docs.docker.com/go/attack-surface/"
  279. echo
  280. echo "================================================================================"
  281. echo
  282. }
  283. # Check if this is a forked Linux distro
  284. check_forked() {
  285. # Check for lsb_release command existence, it usually exists in forked distros
  286. if command_exists lsb_release; then
  287. # Check if the `-u` option is supported
  288. set +e
  289. lsb_release -a -u > /dev/null 2>&1
  290. lsb_release_exit_code=$?
  291. set -e
  292. # Check if the command has exited successfully, it means we're in a forked distro
  293. if [ "$lsb_release_exit_code" = "0" ]; then
  294. # Print info about current distro
  295. cat <<-EOF
  296. You're using '$lsb_dist' version '$dist_version'.
  297. EOF
  298. # Get the upstream release info
  299. lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
  300. dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
  301. # Print info about upstream distro
  302. cat <<-EOF
  303. Upstream release is '$lsb_dist' version '$dist_version'.
  304. EOF
  305. else
  306. if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
  307. if [ "$lsb_dist" = "osmc" ]; then
  308. # OSMC runs Raspbian
  309. lsb_dist=raspbian
  310. else
  311. # We're Debian and don't even know it!
  312. lsb_dist=debian
  313. fi
  314. dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
  315. case "$dist_version" in
  316. 12)
  317. dist_version="bookworm"
  318. ;;
  319. 11)
  320. dist_version="bullseye"
  321. ;;
  322. 10)
  323. dist_version="buster"
  324. ;;
  325. 9)
  326. dist_version="stretch"
  327. ;;
  328. 8)
  329. dist_version="jessie"
  330. ;;
  331. esac
  332. fi
  333. fi
  334. fi
  335. }
  336. do_install() {
  337. echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
  338. if command_exists docker; then
  339. cat >&2 <<-'EOF'
  340. Warning: the "docker" command appears to already exist on this system.
  341. If you already have Docker installed, this script can cause trouble, which is
  342. why we're displaying this warning and provide the opportunity to cancel the
  343. installation.
  344. If you installed the current Docker package using this script and are using it
  345. again to update Docker, you can safely ignore this message.
  346. You may press Ctrl+C now to abort this script.
  347. EOF
  348. ( set -x; sleep 20 )
  349. fi
  350. user="$(id -un 2>/dev/null || true)"
  351. sh_c='sh -c'
  352. if [ "$user" != 'root' ]; then
  353. if command_exists sudo; then
  354. sh_c='sudo -E sh -c'
  355. elif command_exists su; then
  356. sh_c='su -c'
  357. else
  358. cat >&2 <<-'EOF'
  359. Error: this installer needs the ability to run commands as root.
  360. We are unable to find either "sudo" or "su" available to make this happen.
  361. EOF
  362. exit 1
  363. fi
  364. fi
  365. if is_dry_run; then
  366. sh_c="echo"
  367. fi
  368. # perform some very rudimentary platform detection
  369. lsb_dist=$( get_distribution )
  370. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  371. if is_wsl; then
  372. echo
  373. echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
  374. echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop/"
  375. echo
  376. cat >&2 <<-'EOF'
  377. You may press Ctrl+C now to abort this script.
  378. EOF
  379. ( set -x; sleep 20 )
  380. fi
  381. case "$lsb_dist" in
  382. ubuntu)
  383. if command_exists lsb_release; then
  384. dist_version="$(lsb_release --codename | cut -f2)"
  385. fi
  386. if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
  387. dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
  388. fi
  389. ;;
  390. debian|raspbian)
  391. dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
  392. case "$dist_version" in
  393. 12)
  394. dist_version="bookworm"
  395. ;;
  396. 11)
  397. dist_version="bullseye"
  398. ;;
  399. 10)
  400. dist_version="buster"
  401. ;;
  402. 9)
  403. dist_version="stretch"
  404. ;;
  405. 8)
  406. dist_version="jessie"
  407. ;;
  408. esac
  409. ;;
  410. centos|rhel|sles)
  411. if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
  412. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  413. fi
  414. ;;
  415. *)
  416. if command_exists lsb_release; then
  417. dist_version="$(lsb_release --release | cut -f2)"
  418. fi
  419. if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
  420. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  421. fi
  422. ;;
  423. esac
  424. # Check if this is a forked Linux distro
  425. check_forked
  426. # Print deprecation warnings for distro versions that recently reached EOL,
  427. # but may still be commonly used (especially LTS versions).
  428. case "$lsb_dist.$dist_version" in
  429. debian.stretch|debian.jessie)
  430. deprecation_notice "$lsb_dist" "$dist_version"
  431. ;;
  432. raspbian.stretch|raspbian.jessie)
  433. deprecation_notice "$lsb_dist" "$dist_version"
  434. ;;
  435. ubuntu.xenial|ubuntu.trusty)
  436. deprecation_notice "$lsb_dist" "$dist_version"
  437. ;;
  438. ubuntu.impish|ubuntu.hirsute|ubuntu.groovy|ubuntu.eoan|ubuntu.disco|ubuntu.cosmic)
  439. deprecation_notice "$lsb_dist" "$dist_version"
  440. ;;
  441. fedora.*)
  442. if [ "$dist_version" -lt 36 ]; then
  443. deprecation_notice "$lsb_dist" "$dist_version"
  444. fi
  445. ;;
  446. esac
  447. # Run setup for each distro accordingly
  448. case "$lsb_dist" in
  449. ubuntu|debian|raspbian)
  450. pre_reqs="apt-transport-https ca-certificates curl"
  451. if ! command -v gpg > /dev/null; then
  452. pre_reqs="$pre_reqs gnupg"
  453. fi
  454. apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"
  455. (
  456. if ! is_dry_run; then
  457. set -x
  458. fi
  459. $sh_c 'apt-get update -qq >/dev/null'
  460. $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
  461. $sh_c 'install -m 0755 -d /etc/apt/keyrings'
  462. $sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg"
  463. $sh_c "chmod a+r /etc/apt/keyrings/docker.gpg"
  464. $sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
  465. $sh_c 'apt-get update -qq >/dev/null'
  466. )
  467. pkg_version=""
  468. if [ -n "$VERSION" ]; then
  469. if is_dry_run; then
  470. echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
  471. else
  472. # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
  473. pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/~ce~.*/g' | sed 's/-/.*/g')"
  474. search_command="apt-cache madison docker-ce | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
  475. pkg_version="$($sh_c "$search_command")"
  476. echo "INFO: Searching repository for VERSION '$VERSION'"
  477. echo "INFO: $search_command"
  478. if [ -z "$pkg_version" ]; then
  479. echo
  480. echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
  481. echo
  482. exit 1
  483. fi
  484. if version_gte "18.09"; then
  485. search_command="apt-cache madison docker-ce-cli | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
  486. echo "INFO: $search_command"
  487. cli_pkg_version="=$($sh_c "$search_command")"
  488. fi
  489. pkg_version="=$pkg_version"
  490. fi
  491. fi
  492. (
  493. pkgs="docker-ce${pkg_version%=}"
  494. if version_gte "18.09"; then
  495. # older versions didn't ship the cli and containerd as separate packages
  496. pkgs="$pkgs docker-ce-cli${cli_pkg_version%=} containerd.io"
  497. fi
  498. if version_gte "20.10"; then
  499. pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
  500. fi
  501. if version_gte "23.0"; then
  502. pkgs="$pkgs docker-buildx-plugin"
  503. fi
  504. if ! is_dry_run; then
  505. set -x
  506. fi
  507. $sh_c "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pkgs >/dev/null"
  508. )
  509. echo_docker_as_nonroot
  510. exit 0
  511. ;;
  512. centos|fedora|rhel)
  513. if [ "$(uname -m)" != "s390x" ] && [ "$lsb_dist" = "rhel" ]; then
  514. echo "Packages for RHEL are currently only available for s390x."
  515. exit 1
  516. fi
  517. if [ "$lsb_dist" = "fedora" ]; then
  518. pkg_manager="dnf"
  519. config_manager="dnf config-manager"
  520. enable_channel_flag="--set-enabled"
  521. disable_channel_flag="--set-disabled"
  522. pre_reqs="dnf-plugins-core"
  523. pkg_suffix="fc$dist_version"
  524. else
  525. pkg_manager="yum"
  526. config_manager="yum-config-manager"
  527. enable_channel_flag="--enable"
  528. disable_channel_flag="--disable"
  529. pre_reqs="yum-utils"
  530. pkg_suffix="el"
  531. fi
  532. repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
  533. (
  534. if ! is_dry_run; then
  535. set -x
  536. fi
  537. $sh_c "$pkg_manager install -y -q $pre_reqs"
  538. $sh_c "$config_manager --add-repo $repo_file_url"
  539. if [ "$CHANNEL" != "stable" ]; then
  540. $sh_c "$config_manager $disable_channel_flag 'docker-ce-*'"
  541. $sh_c "$config_manager $enable_channel_flag 'docker-ce-$CHANNEL'"
  542. fi
  543. $sh_c "$pkg_manager makecache"
  544. )
  545. pkg_version=""
  546. if [ -n "$VERSION" ]; then
  547. if is_dry_run; then
  548. echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
  549. else
  550. pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g').*$pkg_suffix"
  551. search_command="$pkg_manager list --showduplicates docker-ce | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
  552. pkg_version="$($sh_c "$search_command")"
  553. echo "INFO: Searching repository for VERSION '$VERSION'"
  554. echo "INFO: $search_command"
  555. if [ -z "$pkg_version" ]; then
  556. echo
  557. echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
  558. echo
  559. exit 1
  560. fi
  561. if version_gte "18.09"; then
  562. # older versions don't support a cli package
  563. search_command="$pkg_manager list --showduplicates docker-ce-cli | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
  564. cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
  565. fi
  566. # Cut out the epoch and prefix with a '-'
  567. pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
  568. fi
  569. fi
  570. (
  571. pkgs="docker-ce$pkg_version"
  572. if version_gte "18.09"; then
  573. # older versions didn't ship the cli and containerd as separate packages
  574. if [ -n "$cli_pkg_version" ]; then
  575. pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
  576. else
  577. pkgs="$pkgs docker-ce-cli containerd.io"
  578. fi
  579. fi
  580. if version_gte "20.10"; then
  581. pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
  582. fi
  583. if version_gte "23.0"; then
  584. pkgs="$pkgs docker-buildx-plugin"
  585. fi
  586. if ! is_dry_run; then
  587. set -x
  588. fi
  589. $sh_c "$pkg_manager install -y -q $pkgs"
  590. )
  591. echo_docker_as_nonroot
  592. exit 0
  593. ;;
  594. sles)
  595. if [ "$(uname -m)" != "s390x" ]; then
  596. echo "Packages for SLES are currently only available for s390x"
  597. exit 1
  598. fi
  599. if [ "$dist_version" = "15.3" ]; then
  600. sles_version="SLE_15_SP3"
  601. else
  602. sles_minor_version="${dist_version##*.}"
  603. sles_version="15.$sles_minor_version"
  604. fi
  605. repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
  606. pre_reqs="ca-certificates curl libseccomp2 awk"
  607. (
  608. if ! is_dry_run; then
  609. set -x
  610. fi
  611. $sh_c "zypper install -y $pre_reqs"
  612. $sh_c "zypper addrepo $repo_file_url"
  613. if ! is_dry_run; then
  614. cat >&2 <<-'EOF'
  615. WARNING!!
  616. openSUSE repository (https://download.opensuse.org/repositories/security:SELinux) will be enabled now.
  617. Do you wish to continue?
  618. You may press Ctrl+C now to abort this script.
  619. EOF
  620. ( set -x; sleep 30 )
  621. fi
  622. opensuse_repo="https://download.opensuse.org/repositories/security:SELinux/$sles_version/security:SELinux.repo"
  623. $sh_c "zypper addrepo $opensuse_repo"
  624. $sh_c "zypper --gpg-auto-import-keys refresh"
  625. $sh_c "zypper lr -d"
  626. )
  627. pkg_version=""
  628. if [ -n "$VERSION" ]; then
  629. if is_dry_run; then
  630. echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
  631. else
  632. pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g')"
  633. search_command="zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
  634. pkg_version="$($sh_c "$search_command")"
  635. echo "INFO: Searching repository for VERSION '$VERSION'"
  636. echo "INFO: $search_command"
  637. if [ -z "$pkg_version" ]; then
  638. echo
  639. echo "ERROR: '$VERSION' not found amongst zypper list results"
  640. echo
  641. exit 1
  642. fi
  643. search_command="zypper search -s --match-exact 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
  644. # It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
  645. cli_pkg_version="$($sh_c "$search_command")"
  646. pkg_version="-$pkg_version"
  647. fi
  648. fi
  649. (
  650. pkgs="docker-ce$pkg_version"
  651. if version_gte "18.09"; then
  652. if [ -n "$cli_pkg_version" ]; then
  653. # older versions didn't ship the cli and containerd as separate packages
  654. pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
  655. else
  656. pkgs="$pkgs docker-ce-cli containerd.io"
  657. fi
  658. fi
  659. if version_gte "20.10"; then
  660. pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
  661. fi
  662. if version_gte "23.0"; then
  663. pkgs="$pkgs docker-buildx-plugin"
  664. fi
  665. if ! is_dry_run; then
  666. set -x
  667. fi
  668. $sh_c "zypper -q install -y $pkgs"
  669. )
  670. echo_docker_as_nonroot
  671. exit 0
  672. ;;
  673. *)
  674. if [ -z "$lsb_dist" ]; then
  675. if is_darwin; then
  676. echo
  677. echo "ERROR: Unsupported operating system 'macOS'"
  678. echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
  679. echo
  680. exit 1
  681. fi
  682. fi
  683. echo
  684. echo "ERROR: Unsupported distribution '$lsb_dist'"
  685. echo
  686. exit 1
  687. ;;
  688. esac
  689. exit 1
  690. }
  691. # wrapped up in a function so that we have some protection against only getting
  692. # half the file during "curl | sh"
  693. do_install
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...