当前位置:   article > 正文

在centos8中升级并安装最新版本docker-ce_# executing docker install script, commit: c2de081

# executing docker install script, commit: c2de0811708b6d9015ed1a2c80f02c9b7

查看你当前的linux内核版本是否符合官方对linux版本的要求:

uname -r

卸载旧版本(如果安装过旧版本的话):

sudo yum remove docker docker-common docker-selinux docker-engine

安装需要的软件包:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum源:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

或者使用阿里源

  1. sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. sudo yum makecache fast

安装最新版:

sudo yum install docker-ce

启动docker:

sudo systemctl start docker

加入开机启动:

sudo systemctl enable docker

验证安装是否成功:

docker version

第二种方法:使用docker官方脚本安装

1、确保 yum 包更新到最新。

sudo yum update

2、执行 Docker 安装脚本。

curl -fsSL https://get.docker.com/ | sh
  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="c2de0811708b6d9015ed1a2c80f02c9b70c8ce7b"
  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 (unmaintained)
  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 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

执行这个脚本会添加 docker.repo 源并安装 Docker。

3、启动 Docker 进程。

systemctl start docker

4、加入开机启动:

sudo systemctl enable docker

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/747577
推荐阅读
相关标签
  

闽ICP备14008679号