11#! /bin/sh
22set -e
3- # Docker CE for Linux installation script
3+ # Docker Engine for Linux installation script.
44#
5- # See https://docs.docker.com/engine/install/ for the installation steps.
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.
610#
7- # This script is meant for quick & easy install via:
8- # $ curl -fsSL https://get.docker.com -o get-docker.sh
9- # $ sh get-docker.sh
11+ # The script:
1012#
11- # For test builds (ie. release candidates):
12- # $ curl -fsSL https://test.docker.com -o test-docker.sh
13- # $ sh test-docker.sh
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.
1426#
15- # NOTE: Make sure to verify the contents of the script
16- # you downloaded matches the contents of install.sh
17- # located at https://github.com/docker/docker-install
18- # before executing.
27+ # Source code is available at https://github.com/docker/docker-install/
1928#
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+
80+
2081# Git commit from https://github.com/docker/docker-install when
2182# the script was uploaded (Should only be modified by upload job):
22- SCRIPT_COMMIT_SHA=" a8a6b338bdfedd7ddefb96fe3e7fe7d4036d945a "
83+ SCRIPT_COMMIT_SHA=" e5543d473431b782227f8908005543bb4389b8de "
2384
2485# strip "v" prefix if present
2586VERSION=" ${VERSION# v} "
2687
2788# The channel to install from:
28- # * nightly
29- # * test
3089# * stable
90+ # * test
3191# * edge (deprecated)
92+ # * nightly (deprecated)
3293DEFAULT_CHANNEL_VALUE=" stable"
3394if [ -z " $CHANNEL " ]; then
3495 CHANNEL=$DEFAULT_CHANNEL_VALUE
@@ -48,13 +109,21 @@ mirror=''
48109DRY_RUN=${DRY_RUN:- }
49110while [ $# -gt 0 ]; do
50111 case " $1 " in
51- --mirror )
52- mirror =" $2 "
112+ --channel )
113+ CHANNEL =" $2 "
53114 shift
54115 ;;
55116 --dry-run)
56117 DRY_RUN=1
57118 ;;
119+ --mirror)
120+ mirror=" $2 "
121+ shift
122+ ;;
123+ --version)
124+ VERSION=" ${2# v} "
125+ shift
126+ ;;
58127 --* )
59128 echo " Illegal option $1 "
60129 ;;
@@ -69,40 +138,63 @@ case "$mirror" in
69138 AzureChinaCloud)
70139 DOWNLOAD_URL=" https://mirror.azure.cn/docker-ce"
71140 ;;
141+ " " )
142+ ;;
143+ * )
144+ >&2 echo " unknown mirror '$mirror ': use either 'Aliyun', or 'AzureChinaCloud'."
145+ exit 1
146+ ;;
147+ esac
148+
149+ case " $CHANNEL " in
150+ stable|test)
151+ ;;
152+ edge|nightly)
153+ >&2 echo " DEPRECATED: the $CHANNEL channel has been deprecated and is no longer supported by this script."
154+ exit 1
155+ ;;
156+ * )
157+ >&2 echo " unknown CHANNEL '$CHANNEL ': use either stable or test."
158+ exit 1
159+ ;;
72160esac
73161
74162command_exists () {
75163 command -v " $@ " > /dev/null 2>&1
76164}
77165
78- # version_gte checks if the version specified in $VERSION is at least
79- # the given CalVer (YY.MM) version. returns 0 (success) if $VERSION is either
80- # unset (=latest) or newer or equal than the specified version. Returns 1 (fail)
81- # otherwise.
166+ # version_gte checks if the version specified in $VERSION is at least the given
167+ # SemVer (Maj.Minor[.Patch]), or CalVer (YY.MM) version.It returns 0 (success)
168+ # if $VERSION is either unset (=latest) or newer or equal than the specified
169+ # version, or returns 1 (fail) otherwise.
82170#
83171# examples:
84172#
85- # VERSION=20.10
173+ # VERSION=23.0
174+ # version_gte 23.0 // 0 (success)
86175# version_gte 20.10 // 0 (success)
87176# version_gte 19.03 // 0 (success)
88177# version_gte 21.10 // 1 (fail)
89178version_gte () {
90179 if [ -z " $VERSION " ]; then
91180 return 0
92181 fi
93- eval calver_compare " $VERSION " " $1 "
182+ eval version_compare " $VERSION " " $1 "
94183}
95184
96- # calver_compare compares two CalVer (YY.MM) version strings. returns 0 (success)
97- # if version A is newer or equal than version B, or 1 (fail) otherwise. Patch
98- # releases and pre-release (-alpha/-beta) are not taken into account
185+ # version_compare compares two version strings (either SemVer (Major.Minor.Path),
186+ # or CalVer (YY.MM) version strings. It returns 0 (success) if version A is newer
187+ # or equal than version B, or 1 (fail) otherwise. Patch releases and pre-release
188+ # (-alpha/-beta) are not taken into account
99189#
100190# examples:
101191#
102- # calver_compare 20.10 19.03 // 0 (success)
103- # calver_compare 20.10 20.10 // 0 (success)
104- # calver_compare 19.03 20.10 // 1 (fail)
105- calver_compare () (
192+ # version_compare 23.0.0 20.10 // 0 (success)
193+ # version_compare 23.0 20.10 // 0 (success)
194+ # version_compare 20.10 19.03 // 0 (success)
195+ # version_compare 20.10 20.10 // 0 (success)
196+ # version_compare 19.03 20.10 // 1 (fail)
197+ version_compare () (
106198 set +x
107199
108200 yy_a=" $( echo " $1 " | cut -d' .' -f1) "
@@ -115,7 +207,12 @@ calver_compare() (
115207 fi
116208 mm_a=" $( echo " $1 " | cut -d' .' -f2) "
117209 mm_b=" $( echo " $2 " | cut -d' .' -f2) "
118- if [ " ${mm_a# 0} " -lt " ${mm_b# 0} " ]; then
210+
211+ # trim leading zeros to accommodate CalVer
212+ mm_a=" ${mm_a# 0} "
213+ mm_b=" ${mm_b# 0} "
214+
215+ if [ " ${mm_a:- 0} " -lt " ${mm_b:- 0} " ]; then
119216 return 1
120217 fi
121218
@@ -312,7 +409,7 @@ do_install() {
312409 if is_wsl; then
313410 echo
314411 echo " WSL DETECTED: We recommend using Docker Desktop for Windows."
315- echo " Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
412+ echo " Please get Docker Desktop from https://www.docker.com/products/docker-desktop/ "
316413 echo
317414 cat >&2 << -'EOF '
318415
@@ -385,6 +482,9 @@ do_install() {
385482 ubuntu.xenial|ubuntu.trusty)
386483 deprecation_notice " $lsb_dist " " $dist_version "
387484 ;;
485+ ubuntu.impish|ubuntu.hirsute|ubuntu.groovy|ubuntu.eoan|ubuntu.disco|ubuntu.cosmic)
486+ deprecation_notice " $lsb_dist " " $dist_version "
487+ ;;
388488 fedora.* )
389489 if [ " $dist_version " -lt 36 ]; then
390490 deprecation_notice " $lsb_dist " " $dist_version "
@@ -406,7 +506,7 @@ do_install() {
406506 fi
407507 $sh_c ' apt-get update -qq >/dev/null'
408508 $sh_c " DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pre_reqs >/dev/null"
409- $sh_c ' mkdir -p /etc/apt/keyrings && chmod -R 0755 /etc/apt/keyrings'
509+ $sh_c ' install -m 0755 -d /etc/apt/keyrings'
410510 $sh_c " curl -fsSL \" $DOWNLOAD_URL /linux/$lsb_dist /gpg\" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg"
411511 $sh_c " chmod a+r /etc/apt/keyrings/docker.gpg"
412512 $sh_c " echo \" $apt_repo \" > /etc/apt/sources.list.d/docker.list"
@@ -418,8 +518,8 @@ do_install() {
418518 echo " # WARNING: VERSION pinning is not supported in DRY_RUN"
419519 else
420520 # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
421- pkg_pattern=" $( echo " $VERSION " | sed " s/-ce-/~ce~.*/g" | sed " s/-/.*/g" ) "
422- search_command=" apt-cache madison ' docker-ce' | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
521+ pkg_pattern=" $( echo " $VERSION " | sed ' s/-ce-/~ce~.*/g' | sed ' s/-/.*/g' ) "
522+ search_command=" apt-cache madison docker-ce | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
423523 pkg_version=" $( $sh_c " $search_command " ) "
424524 echo " INFO: Searching repository for VERSION '$VERSION '"
425525 echo " INFO: $search_command "
@@ -430,7 +530,7 @@ do_install() {
430530 exit 1
431531 fi
432532 if version_gte " 18.09" ; then
433- search_command=" apt-cache madison ' docker-ce-cli' | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
533+ search_command=" apt-cache madison docker-ce-cli | grep '$pkg_pattern ' | head -1 | awk '{\$ 1=\$ 1};1' | cut -d' ' -f 3"
434534 echo " INFO: $search_command "
435535 cli_pkg_version=" =$( $sh_c " $search_command " ) "
436536 fi
@@ -486,8 +586,8 @@ do_install() {
486586 $sh_c " $config_manager --add-repo $repo_file_url "
487587
488588 if [ " $CHANNEL " != " stable" ]; then
489- $sh_c " $config_manager $disable_channel_flag docker-ce-*"
490- $sh_c " $config_manager $enable_channel_flag docker-ce-$CHANNEL "
589+ $sh_c " $config_manager $disable_channel_flag ' docker-ce-*' "
590+ $sh_c " $config_manager $enable_channel_flag ' docker-ce-$CHANNEL ' "
491591 fi
492592 $sh_c " $pkg_manager makecache"
493593 )
@@ -496,8 +596,8 @@ do_install() {
496596 if is_dry_run; then
497597 echo " # WARNING: VERSION pinning is not supported in DRY_RUN"
498598 else
499- pkg_pattern=" $( echo " $VERSION " | sed " s/-ce-/\\\\ .ce.*/g" | sed " s/-/.*/g" ) .*$pkg_suffix "
500- search_command=" $pkg_manager list --showduplicates ' docker-ce' | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
599+ pkg_pattern=" $( echo " $VERSION " | sed ' s/-ce-/\\\\.ce.*/g' | sed ' s/-/.*/g' ) .*$pkg_suffix "
600+ search_command=" $pkg_manager list --showduplicates docker-ce | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
501601 pkg_version=" $( $sh_c " $search_command " ) "
502602 echo " INFO: Searching repository for VERSION '$VERSION '"
503603 echo " INFO: $search_command "
@@ -509,7 +609,7 @@ do_install() {
509609 fi
510610 if version_gte " 18.09" ; then
511611 # older versions don't support a cli package
512- search_command=" $pkg_manager list --showduplicates ' docker-ce-cli' | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
612+ search_command=" $pkg_manager list --showduplicates docker-ce-cli | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 2}'"
513613 cli_pkg_version=" $( $sh_c " $search_command " | cut -d' :' -f 2) "
514614 fi
515615 # Cut out the epoch and prefix with a '-'
@@ -551,7 +651,6 @@ do_install() {
551651 sles_minor_version=" ${dist_version##* .} "
552652 sles_version=" 15.$sles_minor_version "
553653 fi
554- opensuse_repo=" https://download.opensuse.org/repositories/security:SELinux/$sles_version /security:SELinux.repo"
555654 repo_file_url=" $DOWNLOAD_URL /linux/$lsb_dist /$REPO_FILE "
556655 pre_reqs=" ca-certificates curl libseccomp2 awk"
557656 (
@@ -569,6 +668,7 @@ do_install() {
569668 EOF
570669 ( set -x; sleep 30 )
571670 fi
671+ opensuse_repo=" https://download.opensuse.org/repositories/security:SELinux/$sles_version /security:SELinux.repo"
572672 $sh_c " zypper addrepo $opensuse_repo "
573673 $sh_c " zypper --gpg-auto-import-keys refresh"
574674 $sh_c " zypper lr -d"
@@ -578,7 +678,7 @@ do_install() {
578678 if is_dry_run; then
579679 echo " # WARNING: VERSION pinning is not supported in DRY_RUN"
580680 else
581- pkg_pattern=" $( echo " $VERSION " | sed " s/-ce-/\\\\ .ce.*/g" | sed " s/-/.*/g" ) "
681+ pkg_pattern=" $( echo " $VERSION " | sed ' s/-ce-/\\\\.ce.*/g' | sed ' s/-/.*/g' ) "
582682 search_command=" zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern ' | tail -1 | awk '{print \$ 6}'"
583683 pkg_version=" $( $sh_c " $search_command " ) "
584684 echo " INFO: Searching repository for VERSION '$VERSION '"
0 commit comments