Docker install - linux mint - diff

Created Diff never expires
2 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
755 lines
2 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
755 lines
#!/bin/sh
#!/bin/sh
set -e
set -e
# Docker Engine for Linux installation script.
# Docker Engine for Linux installation script.
#
#
# This script is intended as a convenient way to configure docker's package
# This script is intended as a convenient way to configure docker's package
# repositories and to install Docker Engine, This script is not recommended
# repositories and to install Docker Engine, This script is not recommended
# for production environments. Before running this script, make yourself familiar
# for production environments. Before running this script, make yourself familiar
# with potential risks and limitations, and refer to the installation manual
# with potential risks and limitations, and refer to the installation manual
# at https://docs.docker.com/engine/install/ for alternative installation methods.
# at https://docs.docker.com/engine/install/ for alternative installation methods.
#
#
# The script:
# The script:
#
#
# - Requires `root` or `sudo` privileges to run.
# - Requires `root` or `sudo` privileges to run.
# - Attempts to detect your Linux distribution and version and configure your
# - Attempts to detect your Linux distribution and version and configure your
# package management system for you.
# package management system for you.
# - Doesn't allow you to customize most installation parameters.
# - Doesn't allow you to customize most installation parameters.
# - Installs dependencies and recommendations without asking for confirmation.
# - Installs dependencies and recommendations without asking for confirmation.
# - Installs the latest stable release (by default) of Docker CLI, Docker Engine,
# - Installs the latest stable release (by default) of Docker CLI, Docker Engine,
# Docker Buildx, Docker Compose, containerd, and runc. When using this script
# Docker Buildx, Docker Compose, containerd, and runc. When using this script
# to provision a machine, this may result in unexpected major version upgrades
# to provision a machine, this may result in unexpected major version upgrades
# of these packages. Always test upgrades in a test environment before
# of these packages. Always test upgrades in a test environment before
# deploying to your production systems.
# deploying to your production systems.
# - Isn't designed to upgrade an existing Docker installation. When using the
# - Isn't designed to upgrade an existing Docker installation. When using the
# script to update an existing installation, dependencies may not be updated
# script to update an existing installation, dependencies may not be updated
# to the expected version, resulting in outdated versions.
# to the expected version, resulting in outdated versions.
#
#
# Source code is available at https://github.com/docker/docker-install/
# Source code is available at https://github.com/docker/docker-install/
#
#
# Usage
# Usage
# ==============================================================================
# ==============================================================================
#
#
# To install the latest stable versions of Docker CLI, Docker Engine, and their
# To install the latest stable versions of Docker CLI, Docker Engine, and their
# dependencies:
# dependencies:
#
#
# 1. download the script
# 1. download the script
#
#
# $ curl -fsSL https://get.docker.com -o install-docker.sh
# $ curl -fsSL https://get.docker.com -o install-docker.sh
#
#
# 2. verify the script's content
# 2. verify the script's content
#
#
# $ cat install-docker.sh
# $ cat install-docker.sh
#
#
# 3. run the script with --dry-run to verify the steps it executes
# 3. run the script with --dry-run to verify the steps it executes
#
#
# $ sh install-docker.sh --dry-run
# $ sh install-docker.sh --dry-run
#
#
# 4. run the script either as root, or using sudo to perform the installation.
# 4. run the script either as root, or using sudo to perform the installation.
#
#
# $ sudo sh install-docker.sh
# $ sudo sh install-docker.sh
#
#
# Command-line options
# Command-line options
# ==============================================================================
# ==============================================================================
#
#
# --version <VERSION>
# --version <VERSION>
# Use the --version option to install a specific version, for example:
# Use the --version option to install a specific version, for example:
#
#
# $ sudo sh install-docker.sh --version 23.0
# $ sudo sh install-docker.sh --version 23.0
#
#
# --channel <stable|test>
# --channel <stable|test>
#
#
# Use the --channel option to install from an alternative installation channel.
# Use the --channel option to install from an alternative installation channel.
# The following example installs the latest versions from the "test" channel,
# The following example installs the latest versions from the "test" channel,
# which includes pre-releases (alpha, beta, rc):
# which includes pre-releases (alpha, beta, rc):
#
#
# $ sudo sh install-docker.sh --channel test
# $ sudo sh install-docker.sh --channel test
#
#
# Alternatively, use the script at https://test.docker.com, which uses the test
# Alternatively, use the script at https://test.docker.com, which uses the test
# channel as default.
# channel as default.
#
#
# --mirror <Aliyun|AzureChinaCloud>
# --mirror <Aliyun|AzureChinaCloud>
#
#
# Use the --mirror option to install from a mirror supported by this script.
# Use the --mirror option to install from a mirror supported by this script.
# Available mirrors are "Aliyun" (https://mirrors.aliyun.com/docker-ce), and
# Available mirrors are "Aliyun" (https://mirrors.aliyun.com/docker-ce), and
# "AzureChinaCloud" (https://mirror.azure.cn/docker-ce), for example:
# "AzureChinaCloud" (https://mirror.azure.cn/docker-ce), for example:
#
#
# $ sudo sh install-docker.sh --mirror AzureChinaCloud
# $ sudo sh install-docker.sh --mirror AzureChinaCloud
#
#
# ==============================================================================
# ==============================================================================




# Git commit from https://github.com/docker/docker-install when
# Git commit from https://github.com/docker/docker-install when
# the script was uploaded (Should only be modified by upload job):
# the script was uploaded (Should only be modified by upload job):
SCRIPT_COMMIT_SHA="4c94a56999e10efcf48c5b8e3f6afea464f9108e"
SCRIPT_COMMIT_SHA="4c94a56999e10efcf48c5b8e3f6afea464f9108e"


# strip "v" prefix if present
# strip "v" prefix if present
VERSION="${VERSION#v}"
VERSION="${VERSION#v}"


# The channel to install from:
# The channel to install from:
# * stable
# * stable
# * test
# * test
DEFAULT_CHANNEL_VALUE="stable"
DEFAULT_CHANNEL_VALUE="stable"
if [ -z "$CHANNEL" ]; then
if [ -z "$CHANNEL" ]; then
CHANNEL=$DEFAULT_CHANNEL_VALUE
CHANNEL=$DEFAULT_CHANNEL_VALUE
fi
fi


DEFAULT_DOWNLOAD_URL="https://download.docker.com"
DEFAULT_DOWNLOAD_URL="https://download.docker.com"
if [ -z "$DOWNLOAD_URL" ]; then
if [ -z "$DOWNLOAD_URL" ]; then
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
fi
fi


DEFAULT_REPO_FILE="docker-ce.repo"
DEFAULT_REPO_FILE="docker-ce.repo"
if [ -z "$REPO_FILE" ]; then
if [ -z "$REPO_FILE" ]; then
REPO_FILE="$DEFAULT_REPO_FILE"
REPO_FILE="$DEFAULT_REPO_FILE"
fi
fi


mirror=''
mirror=''
DRY_RUN=${DRY_RUN:-}
DRY_RUN=${DRY_RUN:-}
while [ $# -gt 0 ]; do
while [ $# -gt 0 ]; do
case "$1" in
case "$1" in
--channel)
--channel)
CHANNEL="$2"
CHANNEL="$2"
shift
shift
;;
;;
--dry-run)
--dry-run)
DRY_RUN=1
DRY_RUN=1
;;
;;
--mirror)
--mirror)
mirror="$2"
mirror="$2"
shift
shift
;;
;;
--version)
--version)
VERSION="${2#v}"
VERSION="${2#v}"
shift
shift
;;
;;
--*)
--*)
echo "Illegal option $1"
echo "Illegal option $1"
;;
;;
esac
esac
shift $(( $# > 0 ? 1 : 0 ))
shift $(( $# > 0 ? 1 : 0 ))
done
done


case "$mirror" in
case "$mirror" in
Aliyun)
Aliyun)
DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
;;
;;
AzureChinaCloud)
AzureChinaCloud)
DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
;;
;;
"")
"")
;;
;;
*)
*)
>&2 echo "unknown mirror '$mirror': use either 'Aliyun', or 'AzureChinaCloud'."
>&2 echo "unknown mirror '$mirror': use either 'Aliyun', or 'AzureChinaCloud'."
exit 1
exit 1
;;
;;
esac
esac


case "$CHANNEL" in
case "$CHANNEL" in
stable|test)
stable|test)
;;
;;
*)
*)
>&2 echo "unknown CHANNEL '$CHANNEL': use either stable or test."
>&2 echo "unknown CHANNEL '$CHANNEL': use either stable or test."
exit 1
exit 1
;;
;;
esac
esac


command_exists() {
command_exists() {
command -v "$@" > /dev/null 2>&1
command -v "$@" > /dev/null 2>&1
}
}


# version_gte checks if the version specified in $VERSION is at least the given
# version_gte checks if the version specified in $VERSION is at least the given
# SemVer (Maj.Minor[.Patch]), or CalVer (YY.MM) version.It returns 0 (success)
# SemVer (Maj.Minor[.Patch]), or CalVer (YY.MM) version.It returns 0 (success)
# if $VERSION is either unset (=latest) or newer or equal than the specified
# if $VERSION is either unset (=latest) or newer or equal than the specified
# version, or returns 1 (fail) otherwise.
# version, or returns 1 (fail) otherwise.
#
#
# examples:
# examples:
#
#
# VERSION=23.0
# VERSION=23.0
# version_gte 23.0 // 0 (success)
# version_gte 23.0 // 0 (success)
# version_gte 20.10 // 0 (success)
# version_gte 20.10 // 0 (success)
# version_gte 19.03 // 0 (success)
# version_gte 19.03 // 0 (success)
# version_gte 26.1 // 1 (fail)
# version_gte 26.1 // 1 (fail)
version_gte() {
version_gte() {
if [ -z "$VERSION" ]; then
if [ -z "$VERSION" ]; then
return 0
return 0
fi
fi
version_compare "$VERSION" "$1"
version_compare "$VERSION" "$1"
}
}


# version_compare compares two version strings (either SemVer (Major.Minor.Path),
# version_compare compares two version strings (either SemVer (Major.Minor.Path),
# or CalVer (YY.MM) version strings. It returns 0 (success) if version A is newer
# or CalVer (YY.MM) version strings. It returns 0 (success) if version A is newer
# or equal than version B, or 1 (fail) otherwise. Patch releases and pre-release
# or equal than version B, or 1 (fail) otherwise. Patch releases and pre-release
# (-alpha/-beta) are not taken into account
# (-alpha/-beta) are not taken into account
#
#
# examples:
# examples:
#
#
# version_compare 23.0.0 20.10 // 0 (success)
# version_compare 23.0.0 20.10 // 0 (success)
# version_compare 23.0 20.10 // 0 (success)
# version_compare 23.0 20.10 // 0 (success)
# version_compare 20.10 19.03 // 0 (success)
# version_compare 20.10 19.03 // 0 (success)
# version_compare 20.10 20.10 // 0 (success)
# version_compare 20.10 20.10 // 0 (success)
# version_compare 19.03 20.10 // 1 (fail)
# version_compare 19.03 20.10 // 1 (fail)
version_compare() (
version_compare() (
set +x
set +x


yy_a="$(echo "$1" | cut -d'.' -f1)"
yy_a="$(echo "$1" | cut -d'.' -f1)"
yy_b="$(echo "$2" | cut -d'.' -f1)"
yy_b="$(echo "$2" | cut -d'.' -f1)"
if [ "$yy_a" -lt "$yy_b" ]; then
if [ "$yy_a" -lt "$yy_b" ]; then
return 1
return 1
fi
fi
if [ "$yy_a" -gt "$yy_b" ]; then
if [ "$yy_a" -gt "$yy_b" ]; then
return 0
return 0
fi
fi
mm_a="$(echo "$1" | cut -d'.' -f2)"
mm_a="$(echo "$1" | cut -d'.' -f2)"
mm_b="$(echo "$2" | cut -d'.' -f2)"
mm_b="$(echo "$2" | cut -d'.' -f2)"


# trim leading zeros to accommodate CalVer
# trim leading zeros to accommodate CalVer
mm_a="${mm_a#0}"
mm_a="${mm_a#0}"
mm_b="${mm_b#0}"
mm_b="${mm_b#0}"


if [ "${mm_a:-0}" -lt "${mm_b:-0}" ]; then
if [ "${mm_a:-0}" -lt "${mm_b:-0}" ]; then
return 1
return 1
fi
fi


return 0
return 0
)
)


is_dry_run() {
is_dry_run() {
if [ -z "$DRY_RUN" ]; then
if [ -z "$DRY_RUN" ]; then
return 1
return 1
else
else
return 0
return 0
fi
fi
}
}


is_wsl() {
is_wsl() {
case "$(uname -r)" in
case "$(uname -r)" in
*microsoft* ) true ;; # WSL 2
*microsoft* ) true ;; # WSL 2
*Microsoft* ) true ;; # WSL 1
*Microsoft* ) true ;; # WSL 1
* ) false;;
* ) false;;
esac
esac
}
}


is_darwin() {
is_darwin() {
case "$(uname -s)" in
case "$(uname -s)" in
*darwin* ) true ;;
*darwin* ) true ;;
*Darwin* ) true ;;
*Darwin* ) true ;;
* ) false;;
* ) false;;
esac
esac
}
}


deprecation_notice() {
deprecation_notice() {
distro=$1
distro=$1
distro_version=$2
distro_version=$2
echo
echo
printf "\033[91;1mDEPRECATION WARNING\033[0m\n"
printf "\033[91;1mDEPRECATION WARNING\033[0m\n"
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"
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"
echo " No updates or security fixes will be released for this distribution, and users are recommended"
echo " No updates or security fixes will be released for this distribution, and users are recommended"
echo " to upgrade to a currently maintained version of $distro."
echo " to upgrade to a currently maintained version of $distro."
echo
echo
printf "Press \033[1mCtrl+C\033[0m now to abort this script, or wait for the installation to continue."
printf "Press \033[1mCtrl+C\033[0m now to abort this script, or wait for the installation to continue."
echo
echo
sleep 10
sleep 10
}
}


get_distribution() {
get_distribution() {
lsb_dist=""
lsb_dist=""
# Every system that we officially support has /etc/os-release
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
fi
# Returning an empty string here should be alright since the
# Returning an empty string here should be alright since the
# case statements don't act unless you provide an actual value
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
echo "$lsb_dist"
}
}


echo_docker_as_nonroot() {
echo_docker_as_nonroot() {
if is_dry_run; then
if is_dry_run; then
return
return
fi
fi
if command_exists docker && [ -e /var/run/docker.sock ]; then
if command_exists docker && [ -e /var/run/docker.sock ]; then
(
(
set -x
set -x
$sh_c 'docker version'
$sh_c 'docker version'
) || true
) || true
fi
fi


# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
echo
echo
echo "================================================================================"
echo "================================================================================"
echo
echo
if version_gte "20.10"; then
if version_gte "20.10"; then
echo "To run Docker as a non-privileged user, consider setting up the"
echo "To run Docker as a non-privileged user, consider setting up the"
echo "Docker daemon in rootless mode for your user:"
echo "Docker daemon in rootless mode for your user:"
echo
echo
echo " dockerd-rootless-setuptool.sh install"
echo " dockerd-rootless-setuptool.sh install"
echo
echo
echo "Visit https://docs.docker.com/go/rootless/ to learn about rootless mode."
echo "Visit https://docs.docker.com/go/rootless/ to learn about rootless mode."
echo
echo
fi
fi
echo
echo
echo "To run the Docker daemon as a fully privileged service, but granting non-root"
echo "To run the Docker daemon as a fully privileged service, but granting non-root"
echo "users access, refer to https://docs.docker.com/go/daemon-access/"
echo "users access, refer to https://docs.docker.com/go/daemon-access/"
echo
echo
echo "WARNING: Access to the remote API on a privileged Docker daemon is equivalent"
echo "WARNING: Access to the remote API on a privileged Docker daemon is equivalent"
echo " to root access on the host. Refer to the 'Docker daemon attack surface'"
echo " to root access on the host. Refer to the 'Docker daemon attack surface'"
echo " documentation for details: https://docs.docker.com/go/attack-surface/"
echo " documentation for details: https://docs.docker.com/go/attack-surface/"
echo
echo
echo "================================================================================"
echo "================================================================================"
echo
echo
}
}


# Check if this is a forked Linux distro
# Check if this is a forked Linux distro
check_forked() {
check_forked() {


# Check for lsb_release command existence, it usually exists in forked distros
# Check for lsb_release command existence, it usually exists in forked distros
if command_exists lsb_release; then
if command_exists lsb_release; then
# Check if the `-u` option is supported
# Check if the `-u` option is supported
set +e
set +e
lsb_release -a -u > /dev/null 2>&1
lsb_release -a -u > /dev/null 2>&1
lsb_release_exit_code=$?
lsb_release_exit_code=$?
set -e
set -e


# Check if the command has exited successfully, it means we're in a forked distro
# Check if the command has exited successfully, it means we're in a forked distro
if [ "$lsb_release_exit_code" = "0" ]; then
if [ "$lsb_release_exit_code" = "0" ]; then
# Print info about current distro
# Print info about current distro
cat <<-EOF
cat <<-EOF
You're using '$lsb_dist' version '$dist_version'.
You're using '$lsb_dist' version '$dist_version'.
EOF
EOF


# Get the upstream release info
# Get the upstream release info
lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')


# Print info about upstream distro
# Print info about upstream distro
cat <<-EOF
cat <<-EOF
Upstream release is '$lsb_dist' version '$dist_version'.
Upstream release is '$lsb_dist' version '$dist_version'.
EOF
EOF
else
else
if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
if [ "$lsb_dist" = "osmc" ]; then
if [ "$lsb_dist" = "osmc" ]; then
# OSMC runs Raspbian
# OSMC runs Raspbian
lsb_dist=raspbian
lsb_dist=raspbian
else
else
# We're Debian and don't even know it!
# We're Debian and don't even know it!
lsb_dist=debian
lsb_dist=debian
fi
fi
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
case "$dist_version" in
12)
12)
dist_version="bookworm"
dist_version="bookworm"
;;
;;
11)
11)
dist_version="bullseye"
dist_version="bullseye"
;;
;;
10)
10)
dist_version="buster"
dist_version="buster"
;;
;;
9)
9)
dist_version="stretch"
dist_version="stretch"
;;
;;
8)
8)
dist_version="jessie"
dist_version="jessie"
;;
;;
esac
esac
fi
fi
fi
fi
fi
fi
}
}


do_install() {
do_install() {
echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"


if command_exists docker; then
if command_exists docker; then
cat >&2 <<-'EOF'
cat >&2 <<-'EOF'
Warning: the "docker" command appears to already exist on this system.
Warning: the "docker" command appears to already exist on this system.


If you already have Docker installed, this script can cause trouble, which is
If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
why we're displaying this warning and provide the opportunity to cancel the
installation.
installation.


If you installed the current Docker package using this script and are using it
If you installed the current Docker package using this script and are using it
again to update Docker, you can ignore this message, but be aware that the
again to update Docker, you can ignore this message, but be aware that the
script resets any custom changes in the deb and rpm repo configuration
script resets any custom changes in the deb and rpm repo configuration
files to match the parameters passed to the script.
files to match the parameters passed to the script.


You may press Ctrl+C now to abort this script.
You may press Ctrl+C now to abort this script.
EOF
EOF
( set -x; sleep 20 )
( set -x; sleep 4 )
fi
fi


user="$(id -un 2>/dev/null || true)"
user="$(id -un 2>/dev/null || true)"


sh_c='sh -c'
sh_c='sh -c'
if [ "$user" != 'root' ]; then
if [ "$user" != 'root' ]; then
if command_exists sudo; then
if command_exists sudo; then
sh_c='sudo -E sh -c'
sh_c='sudo -E sh -c'
elif command_exists su; then
elif command_exists su; then
sh_c='su -c'
sh_c='su -c'
else
else
cat >&2 <<-'EOF'
cat >&2 <<-'EOF'
Error: this installer needs the ability to run commands as root.
Error: this installer needs the ability to run commands as root.
We are unable to find either "sudo" or "su" available to make this happen.
We are unable to find either "sudo" or "su" available to make this happen.
EOF
EOF
exit 1
exit 1
fi
fi
fi
fi


if is_dry_run; then
if is_dry_run; then
sh_c="echo"
sh_c="echo"
fi
fi


# perform some very rudimentary platform detection
# perform some very rudimentary platform detection
lsb_dist=$( get_distribution )
lsb_dist=$( get_distribution )
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"


if is_wsl; then
if is_wsl; then
echo
echo
echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
echo "WSL DETECTED: We recommend using Docker Desktop for Windows."
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop/"
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop/"
echo
echo
cat >&2 <<-'EOF'
cat >&2 <<-'EOF'


You may press Ctrl+C now to abort this script.
You may press Ctrl+C now to abort this script.
EOF
EOF
( set -x; sleep 20 )
( set -x; sleep 20 )
fi
fi


case "$lsb_dist" in
case "$lsb_dist" in


ubuntu)
ubuntu)
if command_exists lsb_release; then
if command_exists lsb_release; then
dist_version="$(lsb_release --codename | cut -f2)"
dist_version="$(lsb_release --codename | cut -f2)"
fi
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
fi
fi
;;
;;


debian|raspbian)
debian|raspbian)
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
case "$dist_version" in
12)
12)
dist_version="bookworm"
dist_version="bookworm"
;;
;;
11)
11)
dist_version="bullseye"
dist_version="bullseye"
;;
;;
10)
10)
dist_version="buster"
dist_version="buster"
;;
;;
9)
9)
dist_version="stretch"
dist_version="stretch"
;;
;;
8)
8)
dist_version="jessie"
dist_version="jessie"
;;
;;
esac
esac
;;
;;


centos|rhel)
centos|rhel)
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
fi
;;
;;


*)
*)
if command_exists lsb_release; then
if command_exists lsb_release; then
dist_version="$(lsb_release --release | cut -f2)"
dist_version="$(lsb_release --release | cut -f2)"
fi
fi
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
fi
;;
;;


esac
esac


# Check if this is a forked Linux distro
# Check if this is a forked Linux distro
check_forked
check_forked


# Print deprecation warnings for distro versions that recently reached EOL,
# Print deprecation warnings for distro versions that recently reached EOL,
# but may still be commonly used (especially LTS versions).
# but may still be commonly used (especially LTS versions).
case "$lsb_dist.$dist_version" in
case "$lsb_dist.$dist_version" in
centos.8|centos.7|rhel.7)
centos.8|centos.7|rhel.7)
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
;;
;;
debian.buster|debian.stretch|debian.jessie)
debian.buster|debian.stretch|debian.jessie)
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
;;
;;
raspbian.buster|raspbian.stretch|raspbian.jessie)
raspbian.buster|raspbian.stretch|raspbian.jessie)
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
;;
;;
ubuntu.bionic|ubuntu.xenial|ubuntu.trusty)
ubuntu.bionic|ubuntu.xenial|ubuntu.trusty)
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
;;
;;
ubuntu.mantic|ubuntu.lunar|ubuntu.kinetic|ubuntu.impish|ubuntu.hirsute|ubuntu.groovy|ubuntu.eoan|ubuntu.disco|ubuntu.cosmic)
ubuntu.mantic|ubuntu.lunar|ubuntu.kinetic|ubuntu.impish|ubuntu.hirsute|ubuntu.groovy|ubuntu.eoan|ubuntu.disco|ubuntu.cosmic)
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
;;
;;
fedora.*)
fedora.*)
if [ "$dist_version" -lt 40 ]; then
if [ "$dist_version" -lt 40 ]; then
deprecation_notice "$lsb_dist" "$dist_version"
deprecation_notice "$lsb_dist" "$dist_version"
fi
fi
;;
;;
esac
esac


# Run setup for each distro accordingly
# Run setup for each distro accordingly
case "$lsb_dist" in
case "$lsb_dist" in
ubuntu|debian|raspbian)
ubuntu|debian|raspbian)
pre_reqs="ca-certificates curl"
pre_reqs="ca-certificates curl"
apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"
apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] $DOWNLOAD_URL/linux/$lsb_dist bookworm $CHANNEL"
(
(
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
$sh_c 'apt-get -qq update >/dev/null'
$sh_c 'apt-get -qq update >/dev/null'
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get -y -qq install $pre_reqs >/dev/null"
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get -y -qq install $pre_reqs >/dev/null"
$sh_c 'install -m 0755 -d /etc/apt/keyrings'
$sh_c 'install -m 0755 -d /etc/apt/keyrings'
$sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" -o /etc/apt/keyrings/docker.asc"
$sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" -o /etc/apt/keyrings/docker.asc"
$sh_c "chmod a+r /etc/apt/keyrings/docker.asc"
$sh_c "chmod a+r /etc/apt/keyrings/docker.asc"
$sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
$sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list"
$sh_c 'apt-get -qq update >/dev/null'
$sh_c 'apt-get -qq update >/dev/null'
)
)
pkg_version=""
pkg_version=""
if [ -n "$VERSION" ]; then
if [ -n "$VERSION" ]; then
if is_dry_run; then
if is_dry_run; then
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
else
else
# Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
# Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/~ce~.*/g' | sed 's/-/.*/g')"
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/~ce~.*/g' | sed 's/-/.*/g')"
search_command="apt-cache madison docker-ce | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
search_command="apt-cache madison docker-ce | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
pkg_version="$($sh_c "$search_command")"
pkg_version="$($sh_c "$search_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search_command"
echo "INFO: $search_command"
if [ -z "$pkg_version" ]; then
if [ -z "$pkg_version" ]; then
echo
echo
echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
echo
echo
exit 1
exit 1
fi
fi
if version_gte "18.09"; then
if version_gte "18.09"; then
search_command="apt-cache madison docker-ce-cli | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
search_command="apt-cache madison docker-ce-cli | grep '$pkg_pattern' | head -1 | awk '{\$1=\$1};1' | cut -d' ' -f 3"
echo "INFO: $search_command"
echo "INFO: $search_command"
cli_pkg_version="=$($sh_c "$search_command")"
cli_pkg_version="=$($sh_c "$search_command")"
fi
fi
pkg_version="=$pkg_version"
pkg_version="=$pkg_version"
fi
fi
fi
fi
(
(
pkgs="docker-ce${pkg_version%=}"
pkgs="docker-ce${pkg_version%=}"
if version_gte "18.09"; then
if version_gte "18.09"; then
# older versions didn't ship the cli and containerd as separate packages
# older versions didn't ship the cli and containerd as separate packages
pkgs="$pkgs docker-ce-cli${cli_pkg_version%=} containerd.io"
pkgs="$pkgs docker-ce-cli${cli_pkg_version%=} containerd.io"
fi
fi
if version_gte "20.10"; then
if version_gte "20.10"; then
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
fi
fi
if version_gte "23.0"; then
if version_gte "23.0"; then
pkgs="$pkgs docker-buildx-plugin"
pkgs="$pkgs docker-buildx-plugin"
fi
fi
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get -y -qq install $pkgs >/dev/null"
$sh_c "DEBIAN_FRONTEND=noninteractive apt-get -y -qq install $pkgs >/dev/null"
)
)
echo_docker_as_nonroot
echo_docker_as_nonroot
exit 0
exit 0
;;
;;
centos|fedora|rhel)
centos|fedora|rhel)
repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
(
(
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
if command_exists dnf5; then
if command_exists dnf5; then
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
$sh_c "dnf5 config-manager addrepo --overwrite --save-filename=docker-ce.repo --from-repofile='$repo_file_url'"
$sh_c "dnf5 config-manager addrepo --overwrite --save-filename=docker-ce.repo --from-repofile='$repo_file_url'"


if [ "$CHANNEL" != "stable" ]; then
if [ "$CHANNEL" != "stable" ]; then
$sh_c "dnf5 config-manager setopt \"docker-ce-*.enabled=0\""
$sh_c "dnf5 config-manager setopt \"docker-ce-*.enabled=0\""
$sh_c "dnf5 config-manager setopt \"docker-ce-$CHANNEL.enabled=1\""
$sh_c "dnf5 config-manager setopt \"docker-ce-$CHANNEL.enabled=1\""
fi
fi
$sh_c "dnf makecache"
$sh_c "dnf makecache"
elif command_exists dnf; then
elif command_exists dnf; then
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
$sh_c "dnf config-manager --add-repo $repo_file_url"
$sh_c "dnf config-manager --add-repo $repo_file_url"


if [ "$CHANNEL" != "stable" ]; then
if [ "$CHANNEL" != "stable" ]; then
$sh_c "dnf config-manager --set-disabled \"docker-ce-*\""
$sh_c "dnf config-manager --set-disabled \"docker-ce-*\""
$sh_c "dnf config-manager --set-enabled \"docker-ce-$CHANNEL\""
$sh_c "dnf config-manager --set-enabled \"docker-ce-$CHANNEL\""
fi
fi
$sh_c "dnf makecache"
$sh_c "dnf makecache"
else
else
$sh_c "yum -y -q install yum-utils"
$sh_c "yum -y -q install yum-utils"
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
$sh_c "yum-config-manager --add-repo $repo_file_url"
$sh_c "yum-config-manager --add-repo $repo_file_url"


if [ "$CHANNEL" != "stable" ]; then
if [ "$CHANNEL" != "stable" ]; then
$sh_c "yum-config-manager --disable \"docker-ce-*\""
$sh_c "yum-config-manager --disable \"docker-ce-*\""
$sh_c "yum-config-manager --enable \"docker-ce-$CHANNEL\""
$sh_c "yum-config-manager --enable \"docker-ce-$CHANNEL\""
fi
fi
$sh_c "yum makecache"
$sh_c "yum makecache"
fi
fi
)
)
pkg_version=""
pkg_version=""
if command_exists dnf; then
if command_exists dnf; then
pkg_manager="dnf"
pkg_manager="dnf"
pkg_manager_flags="-y -q --best"
pkg_manager_flags="-y -q --best"
else
else
pkg_manager="yum"
pkg_manager="yum"
pkg_manager_flags="-y -q"
pkg_manager_flags="-y -q"
fi
fi
if [ -n "$VERSION" ]; then
if [ -n "$VERSION" ]; then
if is_dry_run; then
if is_dry_run; then
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
else
else
if [ "$lsb_dist" = "fedora" ]; then
if [ "$lsb_dist" = "fedora" ]; then
pkg_suffix="fc$dist_version"
pkg_suffix="fc$dist_version"
else
else
pkg_suffix="el"
pkg_suffix="el"
fi
fi
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g').*$pkg_suffix"
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g').*$pkg_suffix"
search_command="$pkg_manager list --showduplicates docker-ce | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
search_command="$pkg_manager list --showduplicates docker-ce | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
pkg_version="$($sh_c "$search_command")"
pkg_version="$($sh_c "$search_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search_command"
echo "INFO: $search_command"
if [ -z "$pkg_version" ]; then
if [ -z "$pkg_version" ]; then
echo
echo
echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
echo
echo
exit 1
exit 1
fi
fi
if version_gte "18.09"; then
if version_gte "18.09"; then
# older versions don't support a cli package
# older versions don't support a cli package
search_command="$pkg_manager list --showduplicates docker-ce-cli | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
search_command="$pkg_manager list --showduplicates docker-ce-cli | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
cli_pkg_version="$($sh_c "$search_command" | cut -d':' -f 2)"
fi
fi
# Cut out the epoch and prefix with a '-'
# Cut out the epoch and prefix with a '-'
pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
fi
fi
fi
fi
(
(
pkgs="docker-ce$pkg_version"
pkgs="docker-ce$pkg_version"
if version_gte "18.09"; then
if version_gte "18.09"; then
# older versions didn't ship the cli and containerd as separate packages
# older versions didn't ship the cli and containerd as separate packages
if [ -n "$cli_pkg_version" ]; then
if [ -n "$cli_pkg_version" ]; then
pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
else
else
pkgs="$pkgs docker-ce-cli containerd.io"
pkgs="$pkgs docker-ce-cli containerd.io"
fi
fi
fi
fi
if version_gte "20.10"; then
if version_gte "20.10"; then
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
fi
fi
if version_gte "23.0"; then
if version_gte "23.0"; then
pkgs="$pkgs docker-buildx-plugin"
pkgs="$pkgs docker-buildx-plugin"
fi
fi
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
$sh_c "$pkg_manager $pkg_manager_flags install $pkgs"
$sh_c "$pkg_manager $pkg_manager_flags install $pkgs"
)
)
echo_docker_as_nonroot
echo_docker_as_nonroot
exit 0
exit 0
;;
;;
sles)
sles)
if [ "$(uname -m)" != "s390x" ]; then
if [ "$(uname -m)" != "s390x" ]; then
echo "Packages for SLES are currently only available for s390x"
echo "Packages for SLES are currently only available for s390x"
exit 1
exit 1
fi
fi
repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
repo_file_url="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"
pre_reqs="ca-certificates curl libseccomp2 awk"
pre_reqs="ca-certificates curl libseccomp2 awk"
(
(
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
$sh_c "zypper install -y $pre_reqs"
$sh_c "zypper install -y $pre_reqs"
$sh_c "rm -f /etc/zypp/repos.d/docker-ce-*.repo"
$sh_c "rm -f /etc/zypp/repos.d/docker-ce-*.repo"
$sh_c "zypper addrepo $repo_file_url"
$sh_c "zypper addrepo $repo_file_url"


opensuse_factory_url="https://download.opensuse.org/repositories/security:/SELinux/openSUSE_Factory/"
opensuse_factory_url="https://download.opensuse.org/repositories/security:/SELinux/openSUSE_Factory/"
if ! zypper lr -d | grep -q "${opensuse_factory_url}"; then
if ! zypper lr -d | grep -q "${opensuse_factory_url}"; then
opensuse_repo="${opensuse_factory_url}security:SELinux.repo"
opensuse_repo="${opensuse_factory_url}security:SELinux.repo"
if ! is_dry_run; then
if ! is_dry_run; then
cat >&2 <<- EOF
cat >&2 <<- EOF
WARNING!!
WARNING!!
openSUSE repository ($opensuse_repo) will be enabled now.
openSUSE repository ($opensuse_repo) will be enabled now.
Do you wish to continue?
Do you wish to continue?
You may press Ctrl+C now to abort this script.
You may press Ctrl+C now to abort this script.
EOF
EOF
( set -x; sleep 20 )
( set -x; sleep 20 )
fi
fi
$sh_c "zypper addrepo $opensuse_repo"
$sh_c "zypper addrepo $opensuse_repo"
fi
fi
$sh_c "zypper --gpg-auto-import-keys refresh"
$sh_c "zypper --gpg-auto-import-keys refresh"
$sh_c "zypper lr -d"
$sh_c "zypper lr -d"
)
)
pkg_version=""
pkg_version=""
if [ -n "$VERSION" ]; then
if [ -n "$VERSION" ]; then
if is_dry_run; then
if is_dry_run; then
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
else
else
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g')"
pkg_pattern="$(echo "$VERSION" | sed 's/-ce-/\\\\.ce.*/g' | sed 's/-/.*/g')"
search_command="zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
search_command="zypper search -s --match-exact 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
pkg_version="$($sh_c "$search_command")"
pkg_version="$($sh_c "$search_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search_command"
echo "INFO: $search_command"
if [ -z "$pkg_version" ]; then
if [ -z "$pkg_version" ]; then
echo
echo
echo "ERROR: '$VERSION' not found amongst zypper list results"
echo "ERROR: '$VERSION' not found amongst zypper list results"
echo
echo
exit 1
exit 1
fi
fi
search_command="zypper search -s --match-exact 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
search_command="zypper search -s --match-exact 'docker-ce-cli' | grep '$pkg_pattern' | tail -1 | awk '{print \$6}'"
# It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
# It's okay for cli_pkg_version to be blank, since older versions don't support a cli package
cli_pkg_version="$($sh_c "$search_command")"
cli_pkg_version="$($sh_c "$search_command")"
pkg_version="-$pkg_version"
pkg_version="-$pkg_version"
fi
fi
fi
fi
(
(
pkgs="docker-ce$pkg_version"
pkgs="docker-ce$pkg_version"
if version_gte "18.09"; then
if version_gte "18.09"; then
if [ -n "$cli_pkg_version" ]; then
if [ -n "$cli_pkg_version" ]; then
# older versions didn't ship the cli and containerd as separate packages
# older versions didn't ship the cli and containerd as separate packages
pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
pkgs="$pkgs docker-ce-cli-$cli_pkg_version containerd.io"
else
else
pkgs="$pkgs docker-ce-cli containerd.io"
pkgs="$pkgs docker-ce-cli containerd.io"
fi
fi
fi
fi
if version_gte "20.10"; then
if version_gte "20.10"; then
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
pkgs="$pkgs docker-compose-plugin docker-ce-rootless-extras$pkg_version"
fi
fi
if version_gte "23.0"; then
if version_gte "23.0"; then
pkgs="$pkgs docker-buildx-plugin"
pkgs="$pkgs docker-buildx-plugin"
fi
fi
if ! is_dry_run; then
if ! is_dry_run; then
set -x
set -x
fi
fi
$sh_c "zypper -q install -y $pkgs"
$sh_c "zypper -q install -y $pkgs"
)
)
echo_docker_as_nonroot
echo_docker_as_nonroot
exit 0
exit 0
;;
;;
*)
*)
if [ -z "$lsb_dist" ]; then
if [ -z "$lsb_dist" ]; then
if is_darwin; then
if is_darwin; then
echo
echo
echo "ERROR: Unsupported operating system 'macOS'"
echo "ERROR: Unsupported operating system 'macOS'"
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
echo "Please get Docker Desktop from https://www.docker.com/products/docker-desktop"
echo
echo
exit 1
exit 1
fi
fi
fi
fi
echo
echo
echo "ERROR: Unsupported distribution '$lsb_dist'"
echo "ERROR: Unsupported distribution '$lsb_dist'"
echo
echo
exit 1
exit 1
;;
;;
esac
esac
exit 1
exit 1
}
}


# wrapped up in a function so that we have some protection against only getting
# wrapped up in a function so that we have some protection against only getting
# half the file during "curl | sh"
# half the file during "curl | sh"
do_install
do_install