先参照 此博客 点这里
我在执行 apt installdocker.io 命令时,不能正确的安装 docker client
所以我找了下面的命令,然后执行 docker version 成功了
辅助参照
https://www.jianshu.com/p/d1b2b4240256
https://blog.csdn.net/hookttg/article/details/80625168
执行命令 sudo curl -sSL https://get.docker.com/ | sh
实际的脚本是下面的
#!/bin/sh
set -e
SCRIPT_COMMIT_SHA=36b78b2
DEFAULT_CHANNEL_VALUE="edge"
if [ -z "$CHANNEL" ]; then
CHANNEL=$DEFAULT_CHANNEL_VALUE
fi
DEFAULT_DOWNLOAD_URL="https://download.docker.com"
if [ -z "$DOWNLOAD_URL" ]; then
DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL
fi
DEFAULT_REPO_FILE="docker-ce.repo"
if [ -z "$REPO_FILE" ]; then
REPO_FILE="$DEFAULT_REPO_FILE"
fi
SUPPORT_MAP="
x86_64-centos-
x86_64-fedora-
x86_64-fedora-
x86_64-fedora-
x86_64-debian-wheezy
x86_64-debian-jessie
x86_64-debian-stretch
x86_64-debian-buster
x86_64-ubuntu-trusty
x86_64-ubuntu-xenial
x86_64-ubuntu-bionic
x86_64-ubuntu-artful
s390x-ubuntu-xenial
s390x-ubuntu-bionic
s390x-ubuntu-artful
ppc64le-ubuntu-xenial
ppc64le-ubuntu-bionic
ppc64le-ubuntu-artful
aarch64-ubuntu-xenial
aarch64-ubuntu-bionic
aarch64-debian-jessie
aarch64-debian-stretch
aarch64-debian-buster
aarch64-fedora-
aarch64-fedora-
aarch64-fedora-
aarch64-centos-
armv6l-raspbian-jessie
armv7l-raspbian-jessie
armv6l-raspbian-stretch
armv7l-raspbian-stretch
armv7l-debian-jessie
armv7l-debian-stretch
armv7l-debian-buster
armv7l-ubuntu-trusty
armv7l-ubuntu-xenial
armv7l-ubuntu-bionic
armv7l-ubuntu-artful
"
mirror=''
DRY_RUN=${DRY_RUN:-}
while [ $# -gt ]; do
case "$1" in
--mirror)
mirror="$2"
shift
;;
--dry-run)
DRY_RUN=
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(( $# > ? : ))
done
case "$mirror" in
Aliyun)
DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"
;;
AzureChinaCloud)
DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"
;;
esac
command_exists() {
command -v "$@" > /dev/null >&
}
is_dry_run() {
if [ -z "$DRY_RUN" ]; then
return
else
return
fi
}
deprecation_notice() {
distro=$
date=$
echo
echo "DEPRECATION WARNING:"
echo " The distribution, $distro, will no longer be supported in this script as of $date."
echo " If you feel this is a mistake please submit an issue at https://github.com/docker/docker-install/issues/new"
echo
sleep
}
get_distribution() {
lsb_dist=""
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
# Returning an empty string here should be alright since the
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
}
add_debian_backport_repo() {
debian_version="$1"
backports="deb http://ftp.debian.org/debian $debian_version-backports main"
if ! grep -Fxq "$backports" /etc/apt/sources.list; then
(set -x; $sh_c "echo \"$backports\" >> /etc/apt/sources.list")
fi
}
echo_docker_as_nonroot() {
if is_dry_run; then
return
fi
if command_exists docker && [ -e /var/run/docker.sock ]; then
(
set -x
$sh_c 'docker version'
) || true
fi
your_user=your-user
[ "$user" != 'root' ] && your_user="$user"
# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
echo "If you would like to use Docker as a non-root user, you should now consider"
echo "adding your user to the \"docker\" group with something like:"
echo
echo " sudo usermod -aG docker $your_user"
echo
echo "Remember that you will have to log out and back in for this to take effect!"
echo
echo "WARNING: Adding a user to the \"docker\" group will grant the ability to run"
echo " containers which can be used to obtain root privileges on the"
echo " docker host."
echo " Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"
echo " for more information."
}
check_forked() {
# Check for lsb\_release command existence, it usually exists in forked distros
if command\_exists lsb\_release; then
# Check if the \`-u\` option is supported
set +e
lsb\_release -a -u > /dev/null >&
lsb\_release\_exit\_code=$?
set -e
# Check if the command has exited successfully, it means we're in a forked distro
if \[ "$lsb\_release\_exit\_code" = "" \]; then
# Print info about current distro
cat <<-EOF
You're using '$lsb\_dist' version '$dist\_version'.
EOF
# Get the upstream release info
lsb\_dist=$(lsb\_release -a -u >& | tr '\[:upper:\]' '\[:lower:\]' | grep -E 'id' | cut -d ':' -f | tr -d '\[:space:\]')
dist\_version=$(lsb\_release -a -u >& | tr '\[:upper:\]' '\[:lower:\]' | grep -E 'codename' | cut -d ':' -f | tr -d '\[:space:\]')
# Print info about upstream distro
cat <<-EOF
Upstream release is '$lsb\_dist' version '$dist\_version'.
EOF
else
if \[ -r /etc/debian\_version \] && \[ "$lsb\_dist" != "ubuntu" \] && \[ "$lsb\_dist" != "raspbian" \]; then
if \[ "$lsb\_dist" = "osmc" \]; then
# OSMC runs Raspbian
lsb\_dist=raspbian
else
# We're Debian and don't even know it!
lsb\_dist=debian
fi
dist\_version="$(sed 's/\\/.\*//' /etc/debian\_version | sed 's/\\..\*//')"
case "$dist\_version" in
)
dist\_version="stretch"
;;
|'Kali Linux 2')
dist\_version="jessie"
;;
)
dist\_version="wheezy"
;;
esac
fi
fi
fi
}
semverParse() {
major="${1%%.*}"
minor="${1#$major.}"
minor="${minor%%.*}"
patch="${1#$major.$minor.}"
patch="${patch%%[-.]*}"
}
ee_notice() {
echo
echo
echo " WARNING: $1 is now only supported by Docker EE"
echo " Check https://store.docker.com for information on Docker EE"
echo
echo
}
do_install() {
echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
if command\_exists docker; then
docker\_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
MAJOR\_W=
MINOR\_W=
semverParse "$docker\_version"
shouldWarn=
if \[ "$major" -lt "$MAJOR\_W" \]; then
shouldWarn=
fi
if \[ "$major" -le "$MAJOR\_W" \] && \[ "$minor" -lt "$MINOR\_W" \]; then
shouldWarn=
fi
cat >& <<-'EOF'
Warning: the "docker" command appears to already exist on this system.
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
installation.
If you installed the current Docker package using this script and are using it
EOF
if \[ $shouldWarn -eq \]; then
cat >& <<-'EOF'
again to update Docker, we urge you to migrate your image store before upgrading
to v1.+.
You can find instructions for this here:
https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
EOF
else
cat >& <<-'EOF'
again to update Docker, you can safely ignore this message.
EOF
fi
cat >& <<-'EOF'
You may press Ctrl+C now to abort this script.
EOF
( set -x; sleep )
fi
user="$(id -un 2>/dev/null || true)"
sh\_c='sh -c'
if \[ "$user" != 'root' \]; then
if command\_exists sudo; then
sh\_c='sudo -E sh -c'
elif command\_exists su; then
sh\_c='su -c'
else
cat >& <<-'EOF'
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.
EOF
exit
fi
fi
if is\_dry\_run; then
sh\_c="echo"
fi
# perform some very rudimentary platform detection
lsb\_dist=$( get\_distribution )
lsb\_dist="$(echo "$lsb\_dist" | tr '\[:upper:\]' '\[:lower:\]')"
case "$lsb\_dist" in
ubuntu)
if command\_exists lsb\_release; then
dist\_version="$(lsb\_release --codename | cut -f2)"
fi
if \[ -z "$dist\_version" \] && \[ -r /etc/lsb-release \]; then
dist\_version="$(. /etc/lsb-release && echo "$DISTRIB\_CODENAME")"
fi
;;
debian|raspbian)
dist\_version="$(sed 's/\\/.\*//' /etc/debian\_version | sed 's/\\..\*//')"
case "$dist\_version" in
)
dist\_version="stretch"
;;
)
dist\_version="jessie"
;;
)
dist\_version="wheezy"
;;
esac
;;
centos)
if \[ -z "$dist\_version" \] && \[ -r /etc/os-release \]; then
dist\_version="$(. /etc/os-release && echo "$VERSION\_ID")"
fi
;;
rhel|ol|sles)
ee\_notice "$lsb\_dist"
exit
;;
\*)
if command\_exists lsb\_release; then
dist\_version="$(lsb\_release --release | cut -f2)"
fi
if \[ -z "$dist\_version" \] && \[ -r /etc/os-release \]; then
dist\_version="$(. /etc/os-release && echo "$VERSION\_ID")"
fi
;;
esac
# Check if this is a forked Linux distro
check\_forked
# Check if we actually support this configuration
if ! echo "$SUPPORT\_MAP" | grep "$(uname -m)-$lsb\_dist-$dist\_version" >/dev/null; then
cat >& <<-'EOF'
Either your platform is not easily detectable or is not supported by this
installer script.
Please visit the following URL for more detailed installation instructions:
https://docs.docker.com/engine/installation/
EOF
exit
fi
# Run setup for each distro accordingly
case "$lsb\_dist" in
ubuntu|debian|raspbian)
pre\_reqs="apt-transport-https ca-certificates curl"
if \[ "$lsb\_dist" = "debian" \]; then
if \[ "$dist\_version" = "wheezy" \]; then
add\_debian\_backport\_repo "$dist\_version"
fi
# libseccomp2 does not exist for debian jessie main repos for aarch64
if \[ "$(uname -m)" = "aarch64" \] && \[ "$dist\_version" = "jessie" \]; then
add\_debian\_backport\_repo "$dist\_version"
fi
fi
# TODO: August , delete from here,
if \[ "$lsb\_dist" = "ubuntu" \] && \[ "$dist\_version" = "artful" \]; then
deprecation\_notice "$lsb\_dist $dist\_version" "August 31, 2018"
fi
# TODO: August , delete to here,
if ! command -v gpg > /dev/null; then
pre\_reqs="$pre\_reqs gnupg"
fi
apt\_repo="deb \[arch=$(dpkg --print-architecture)\] $DOWNLOAD\_URL/linux/$lsb\_dist $dist\_version $CHANNEL"
(
if ! is\_dry\_run; then
set -x
fi
$sh\_c 'apt-get update -qq >/dev/null'
$sh\_c "apt-get install -y -qq $pre\_reqs >/dev/null"
$sh\_c "curl -fsSL \\"$DOWNLOAD\_URL/linux/$lsb\_dist/gpg\\" | apt-key add -qq - >/dev/null"
$sh\_c "echo \\"$apt\_repo\\" > /etc/apt/sources.list.d/docker.list"
if \[ "$lsb\_dist" = "debian" \] && \[ "$dist\_version" = "wheezy" \]; then
$sh\_c 'sed -i "/deb-src.\*download\\.docker/d" /etc/apt/sources.list.d/docker.list'
fi
$sh\_c 'apt-get update -qq >/dev/null'
)
pkg\_version=""
if \[ ! -z "$VERSION" \]; then
if is\_dry\_run; then
echo "# WARNING: VERSION pinning is not supported in DRY\_RUN"
else
# 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").\*-0~$lsb\_dist"
search\_command="apt-cache madison 'docker-ce' | grep '$pkg\_pattern' | head -1 | cut -d' ' -f 4"
pkg\_version="$($sh\_c "$search\_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search\_command"
if \[ -z "$pkg\_version" \]; then
echo
echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
echo
exit
fi
pkg\_version="=$pkg\_version"
fi
fi
(
if ! is\_dry\_run; then
set -x
fi
$sh\_c "apt-get install -y -qq --no-install-recommends docker-ce$pkg\_version >/dev/null"
)
echo\_docker\_as\_nonroot
exit
;;
centos|fedora)
yum\_repo="$DOWNLOAD\_URL/linux/$lsb\_dist/$REPO\_FILE"
if ! curl -Ifs "$yum\_repo" > /dev/null; then
echo "Error: Unable to curl repository file $yum\_repo, is it valid?"
exit
fi
if \[ "$lsb\_dist" = "fedora" \]; then
if \[ "$dist\_version" -lt "" \]; then
echo "Error: Only Fedora >=26 are supported"
exit
fi
pkg\_manager="dnf"
config\_manager="dnf config-manager"
enable\_channel\_flag="--set-enabled"
pre\_reqs="dnf-plugins-core"
pkg\_suffix="fc$dist\_version"
else
pkg\_manager="yum"
config\_manager="yum-config-manager"
enable\_channel\_flag="--enable"
pre\_reqs="yum-utils"
pkg\_suffix="el"
fi
(
if ! is\_dry\_run; then
set -x
fi
$sh\_c "$pkg\_manager install -y -q $pre\_reqs"
$sh\_c "$config\_manager --add-repo $yum\_repo"
if \[ "$CHANNEL" != "stable" \]; then
$sh\_c "$config\_manager $enable\_channel\_flag docker-ce-$CHANNEL"
fi
$sh\_c "$pkg\_manager makecache"
)
pkg\_version=""
if \[ ! -z "$VERSION" \]; then
if is\_dry\_run; then
echo "# WARNING: VERSION pinning is not supported in DRY\_RUN"
else
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}'"
pkg\_version="$($sh\_c "$search\_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search\_command"
if \[ -z "$pkg\_version" \]; then
echo
echo "ERROR: '$VERSION' not found amongst $pkg\_manager list results"
echo
exit
fi
# Cut out the epoch and prefix with a '-'
pkg\_version="-$(echo "$pkg\_version" | cut -d':' -f 2)"
fi
fi
(
if ! is\_dry\_run; then
set -x
fi
$sh\_c "$pkg\_manager install -y -q docker-ce$pkg\_version"
)
echo\_docker\_as\_nonroot
exit
;;
esac
exit
}
do_install
手机扫一扫
移动阅读更方便
你可能感兴趣的文章