先上服务器环境信息:
卸载的原因:
宿主机过段时间就磁盘100%了,导致continart异常退出,后来找了很多解决方案,才发现是安装docker的时候有个配置文件错误(正常的应该是|Storage Driver: overlay2)。
上干货:
①卸载
1 yum remove docker \ 2 docker-client \ 3 docker-client-latest \ 4 docker-common \ 5 docker-latest \ 6 docker-latest-logrotate \ 7 docker-logrotate \ 8 docker-selinux \ 9 docker-engine-selinux \ 10 docker-engine 11 12 rm -rf /etc/systemd/system/docker.service.d 13 14 rm -rf /var/lib/docker 15 16 rm -rf /var/run/docker
②安装
1 #!/bin/sh 2 set -e 3 4 # This script is meant for quick & easy install via: 5 # $ curl -fsSL get.docker.com -o get-docker.sh 6 # $ sh get-docker.sh 7 # 8 # For test builds (ie. release candidates): 9 # $ curl -fsSL test.docker.com -o test-docker.sh 10 # $ sh test-docker.sh 11 # 12 # NOTE: Make sure to verify the contents of the script 13 # you downloaded matches the contents of install.sh 14 # located at https://github.com/docker/docker-install 15 # before executing. 16 # 17 # Git commit from https://github.com/docker/docker-install when 18 # the script was uploaded (Should only be modified by upload job): 19 SCRIPT_COMMIT_SHA=36b78b2 20 21 22 # This value will automatically get changed for: 23 # * edge 24 # * test 25 # * experimental 26 DEFAULT_CHANNEL_VALUE="edge" 27 if [ -z "$CHANNEL" ]; then 28 CHANNEL=$DEFAULT_CHANNEL_VALUE 29 fi 30 31 DEFAULT_DOWNLOAD_URL="https://download.docker.com" 32 if [ -z "$DOWNLOAD_URL" ]; then 33 DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL 34 fi 35 36 DEFAULT_REPO_FILE="docker-ce.repo" 37 if [ -z "$REPO_FILE" ]; then 38 REPO_FILE="$DEFAULT_REPO_FILE" 39 fi 40 41 SUPPORT_MAP=" 42 x86_64-centos-7 43 x86_64-fedora-26 44 x86_64-fedora-27 45 x86_64-fedora-28 46 x86_64-debian-wheezy 47 x86_64-debian-jessie 48 x86_64-debian-stretch 49 x86_64-debian-buster 50 x86_64-ubuntu-trusty 51 x86_64-ubuntu-xenial 52 x86_64-ubuntu-bionic 53 x86_64-ubuntu-artful 54 s390x-ubuntu-xenial 55 s390x-ubuntu-bionic 56 s390x-ubuntu-artful 57 ppc64le-ubuntu-xenial 58 ppc64le-ubuntu-bionic 59 ppc64le-ubuntu-artful 60 aarch64-ubuntu-xenial 61 aarch64-ubuntu-bionic 62 aarch64-debian-jessie 63 aarch64-debian-stretch 64 aarch64-debian-buster 65 aarch64-fedora-26 66 aarch64-fedora-27 67 aarch64-fedora-28 68 aarch64-centos-7 69 armv6l-raspbian-jessie 70 armv7l-raspbian-jessie 71 armv6l-raspbian-stretch 72 armv7l-raspbian-stretch 73 armv7l-debian-jessie 74 armv7l-debian-stretch 75 armv7l-debian-buster 76 armv7l-ubuntu-trusty 77 armv7l-ubuntu-xenial 78 armv7l-ubuntu-bionic 79 armv7l-ubuntu-artful 80 " 81 82 mirror='' 83 DRY_RUN=${DRY_RUN:-} 84 while [ $# -gt 0 ]; do 85 case "$1" in 86 --mirror) 87 mirror="$2" 88 shift 89 ;; 90 --dry-run) 91 DRY_RUN=1 92 ;; 93 --*) 94 echo "Illegal option $1" 95 ;; 96 esac 97 shift $(( $# > 0 ? 1 : 0 )) 98 done 99 100 case "$mirror" in 101 Aliyun) 102 DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce" 103 ;; 104 AzureChinaCloud) 105 DOWNLOAD_URL="https://mirror.azure.cn/docker-ce" 106 ;; 107 esac 108 109 command_exists() { 110 command -v "$@" > /dev/null 2>&1 111 } 112 113 is_dry_run() { 114 if [ -z "$DRY_RUN" ]; then 115 return 1 116 else 117 return 0 118 fi 119 } 120 121 deprecation_notice() { 122 distro=$1 123 date=$2 124 echo 125 echo "DEPRECATION WARNING:" 126 echo " The distribution, $distro, will no longer be supported in this script as of $date." 127 echo " If you feel this is a mistake please submit an issue at https://github.com/docker/docker-install/issues/new" 128 echo 129 sleep 10 130 } 131 132 get_distribution() { 133 lsb_dist="" 134 # Every system that we officially support has /etc/os-release 135 if [ -r /etc/os-release ]; then 136 lsb_dist="$(. /etc/os-release && echo "$ID")" 137 fi 138 # Returning an empty string here should be alright since the 139 # case statements don't act unless you provide an actual value 140 echo "$lsb_dist" 141 } 142 143 add_debian_backport_repo() { 144 debian_version="$1" 145 backports="deb http://ftp.debian.org/debian $debian_version-backports main" 146 if ! grep -Fxq "$backports" /etc/apt/sources.list; then 147 (set -x; $sh_c "echo \"$backports\" >> /etc/apt/sources.list") 148 fi 149 } 150 151 echo_docker_as_nonroot() { 152 if is_dry_run; then 153 return 154 fi 155 if command_exists docker && [ -e /var/run/docker.sock ]; then 156 ( 157 set -x 158 $sh_c 'docker version' 159 ) || true 160 fi 161 your_user=your-user 162 [ "$user" != 'root' ] && your_user="$user" 163 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output 164 echo "If you would like to use Docker as a non-root user, you should now consider" 165 echo "adding your user to the \"docker\" group with something like:" 166 echo 167 echo " sudo usermod -aG docker $your_user" 168 echo 169 echo "Remember that you will have to log out and back in for this to take effect!" 170 echo 171 echo "WARNING: Adding a user to the \"docker\" group will grant the ability to run" 172 echo " containers which can be used to obtain root privileges on the" 173 echo " docker host." 174 echo " Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface" 175 echo " for more information." 176 177 } 178 179 # Check if this is a forked Linux distro 180 check_forked() { 181 182 # Check for lsb_release command existence, it usually exists in forked distros 183 if command_exists lsb_release; then 184 # Check if the `-u` option is supported 185 set +e 186 lsb_release -a -u > /dev/null 2>&1 187 lsb_release_exit_code=$? 188 set -e 189 190 # Check if the command has exited successfully, it means we're in a forked distro 191 if [ "$lsb_release_exit_code" = "0" ]; then 192 # Print info about current distro 193 cat <<-EOF 194 You're using '$lsb_dist' version '$dist_version'. 195 EOF 196 197 # Get the upstream release info 198 lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]') 199 dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]') 200 201 # Print info about upstream distro 202 cat <<-EOF 203 Upstream release is '$lsb_dist' version '$dist_version'. 204 EOF 205 else 206 if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then 207 if [ "$lsb_dist" = "osmc" ]; then 208 # OSMC runs Raspbian 209 lsb_dist=raspbian 210 else 211 # We're Debian and don't even know it! 212 lsb_dist=debian 213 fi 214 dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" 215 case "$dist_version" in 216 9) 217 dist_version="stretch" 218 ;; 219 8|'Kali Linux 2') 220 dist_version="jessie" 221 ;; 222 7) 223 dist_version="wheezy" 224 ;; 225 esac 226 fi 227 fi 228 fi 229 } 230 231 semverParse() { 232 major="${1%%.*}" 233 minor="${1#$major.}" 234 minor="${minor%%.*}" 235 patch="${1#$major.$minor.}" 236 patch="${patch%%[-.]*}" 237 } 238 239 ee_notice() { 240 echo 241 echo 242 echo " WARNING: $1 is now only supported by Docker EE" 243 echo " Check https://store.docker.com for information on Docker EE" 244 echo 245 echo 246 } 247 248 do_install() { 249 echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA" 250 251 if command_exists docker; then 252 docker_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)" 253 MAJOR_W=1 254 MINOR_W=10 255 256 semverParse "$docker_version" 257 258 shouldWarn=0 259 if [ "$major" -lt "$MAJOR_W" ]; then 260 shouldWarn=1 261 fi 262 263 if [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; then 264 shouldWarn=1 265 fi 266 267 cat >&2 <<-'EOF' 268 Warning: the "docker" command appears to already exist on this system. 269 270 If you already have Docker installed, this script can cause trouble, which is 271 why we're displaying this warning and provide the opportunity to cancel the 272 installation. 273 274 If you installed the current Docker package using this script and are using it 275 EOF 276 277 if [ $shouldWarn -eq 1 ]; then 278 cat >&2 <<-'EOF' 279 again to update Docker, we urge you to migrate your image store before upgrading 280 to v1.10+. 281 282 You can find instructions for this here: 283 https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration 284 EOF 285 else 286 cat >&2 <<-'EOF' 287 again to update Docker, you can safely ignore this message. 288 EOF 289 fi 290 291 cat >&2 <<-'EOF' 292 293 You may press Ctrl+C now to abort this script. 294 EOF 295 ( set -x; sleep 20 ) 296 fi 297 298 user="$(id -un 2>/dev/null || true)" 299 300 sh_c='sh -c' 301 if [ "$user" != 'root' ]; then 302 if command_exists sudo; then 303 sh_c='sudo -E sh -c' 304 elif command_exists su; then 305 sh_c='su -c' 306 else 307 cat >&2 <<-'EOF' 308 Error: this installer needs the ability to run commands as root. 309 We are unable to find either "sudo" or "su" available to make this happen. 310 EOF 311 exit 1 312 fi 313 fi 314 315 if is_dry_run; then 316 sh_c="echo" 317 fi 318 319 # perform some very rudimentary platform detection 320 lsb_dist=$( get_distribution ) 321 lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" 322 323 case "$lsb_dist" in 324 325 ubuntu) 326 if command_exists lsb_release; then 327 dist_version="$(lsb_release --codename | cut -f2)" 328 fi 329 if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then 330 dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" 331 fi 332 ;; 333 334 debian|raspbian) 335 dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" 336 case "$dist_version" in 337 9) 338 dist_version="stretch" 339 ;; 340 8) 341 dist_version="jessie" 342 ;; 343 7) 344 dist_version="wheezy" 345 ;; 346 esac 347 ;; 348 349 centos) 350 if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then 351 dist_version="$(. /etc/os-release && echo "$VERSION_ID")" 352 fi 353 ;; 354 355 rhel|ol|sles) 356 ee_notice "$lsb_dist" 357 exit 1 358 ;; 359 360 *) 361 if command_exists lsb_release; then 362 dist_version="$(lsb_release --release | cut -f2)" 363 fi 364 if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then 365 dist_version="$(. /etc/os-release && echo "$VERSION_ID")" 366 fi 367 ;; 368 369 esac 370 371 # Check if this is a forked Linux distro 372 check_forked 373 374 # Check if we actually support this configuration 375 if ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; then 376 cat >&2 <<-'EOF' 377 378 Either your platform is not easily detectable or is not supported by this 379 installer script. 380 Please visit the following URL for more detailed installation instructions: 381 382 https://docs.docker.com/engine/installation/ 383 384 EOF 385 exit 1 386 fi 387 388 # Run setup for each distro accordingly 389 case "$lsb_dist" in 390 ubuntu|debian|raspbian) 391 pre_reqs="apt-transport-https ca-certificates curl" 392 if [ "$lsb_dist" = "debian" ]; then 393 if [ "$dist_version" = "wheezy" ]; then 394 add_debian_backport_repo "$dist_version" 395 fi 396 # libseccomp2 does not exist for debian jessie main repos for aarch64 397 if [ "$(uname -m)" = "aarch64" ] && [ "$dist_version" = "jessie" ]; then 398 add_debian_backport_repo "$dist_version" 399 fi 400 fi 401 402 # TODO: August 31, 2018 delete from here, 403 if [ "$lsb_dist" = "ubuntu" ] && [ "$dist_version" = "artful" ]; then 404 deprecation_notice "$lsb_dist $dist_version" "August 31, 2018" 405 fi 406 # TODO: August 31, 2018 delete to here, 407 408 if ! command -v gpg > /dev/null; then 409 pre_reqs="$pre_reqs gnupg" 410 fi 411 apt_repo="deb [arch=$(dpkg --print-architecture)] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL" 412 ( 413 if ! is_dry_run; then 414 set -x 415 fi 416 $sh_c 'apt-get update -qq >/dev/null' 417 $sh_c "apt-get install -y -qq $pre_reqs >/dev/null" 418 $sh_c "curl -fsSL \"$DOWNLOAD_URL/linux/$lsb_dist/gpg\" | apt-key add -qq - >/dev/null" 419 $sh_c "echo \"$apt_repo\" > /etc/apt/sources.list.d/docker.list" 420 if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "wheezy" ]; then 421 $sh_c 'sed -i "/deb-src.*download\.docker/d" /etc/apt/sources.list.d/docker.list' 422 fi 423 $sh_c 'apt-get update -qq >/dev/null' 424 ) 425 pkg_version="" 426 if [ ! -z "$VERSION" ]; then 427 if is_dry_run; then 428 echo "# WARNING: VERSION pinning is not supported in DRY_RUN" 429 else 430 # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel 431 pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/~ce~.*/g" | sed "s/-/.*/g").*-0~$lsb_dist" 432 search_command="apt-cache madison 'docker-ce' | grep '$pkg_pattern' | head -1 | cut -d' ' -f 4" 433 pkg_version="$($sh_c "$search_command")" 434 echo "INFO: Searching repository for VERSION '$VERSION'" 435 echo "INFO: $search_command" 436 if [ -z "$pkg_version" ]; then 437 echo 438 echo "ERROR: '$VERSION' not found amongst apt-cache madison results" 439 echo 440 exit 1 441 fi 442 pkg_version="=$pkg_version" 443 fi 444 fi 445 ( 446 if ! is_dry_run; then 447 set -x 448 fi 449 $sh_c "apt-get install -y -qq --no-install-recommends docker-ce$pkg_version >/dev/null" 450 ) 451 echo_docker_as_nonroot 452 exit 0 453 ;; 454 centos|fedora) 455 yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE" 456 if ! curl -Ifs "$yum_repo" > /dev/null; then 457 echo "Error: Unable to curl repository file $yum_repo, is it valid?" 458 exit 1 459 fi 460 if [ "$lsb_dist" = "fedora" ]; then 461 if [ "$dist_version" -lt "26" ]; then 462 echo "Error: Only Fedora >=26 are supported" 463 exit 1 464 fi 465 466 pkg_manager="dnf" 467 config_manager="dnf config-manager" 468 enable_channel_flag="--set-enabled" 469 pre_reqs="dnf-plugins-core" 470 pkg_suffix="fc$dist_version" 471 else 472 pkg_manager="yum" 473 config_manager="yum-config-manager" 474 enable_channel_flag="--enable" 475 pre_reqs="yum-utils" 476 pkg_suffix="el" 477 fi 478 ( 479 if ! is_dry_run; then 480 set -x 481 fi 482 $sh_c "$pkg_manager install -y -q $pre_reqs" 483 $sh_c "$config_manager --add-repo $yum_repo" 484 485 if [ "$CHANNEL" != "stable" ]; then 486 $sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL" 487 fi 488 $sh_c "$pkg_manager makecache" 489 ) 490 pkg_version="" 491 if [ ! -z "$VERSION" ]; then 492 if is_dry_run; then 493 echo "# WARNING: VERSION pinning is not supported in DRY_RUN" 494 else 495 pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce.*/g" | sed "s/-/.*/g").*$pkg_suffix" 496 search_command="$pkg_manager list --showduplicates 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'" 497 pkg_version="$($sh_c "$search_command")" 498 echo "INFO: Searching repository for VERSION '$VERSION'" 499 echo "INFO: $search_command" 500 if [ -z "$pkg_version" ]; then 501 echo 502 echo "ERROR: '$VERSION' not found amongst $pkg_manager list results" 503 echo 504 exit 1 505 fi 506 # Cut out the epoch and prefix with a '-' 507 pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)" 508 fi 509 fi 510 ( 511 if ! is_dry_run; then 512 set -x 513 fi 514 $sh_c "$pkg_manager install -y -q docker-ce$pkg_version" 515 ) 516 echo_docker_as_nonroot 517 exit 0 518 ;; 519 esac 520 exit 1 521 } 522 523 # wrapped up in a function so that we have some protection against only getting 524 # half the file during "curl | sh" 525 do_install
1 chmod +x getdocker.sh 2 ./getdocker.sh -s docker --mirror Aliyun
getdocker.sh 文件内容在上个代码区域
所有评论(0)