先上服务器环境信息:
卸载的原因:
宿主机过段时间就磁盘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-engine11 12 rm -rf /etc/systemd/system/docker.service.d13 14 rm -rf /var/lib/docker15 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" in101 Aliyun)102 DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce"103 ;;104 AzureChinaCloud)105 DOWNLOAD_URL="https://mirror.azure.cn/docker-ce"106 ;;107 esac108 109 command_exists() {110 command -v "$@" > /dev/null 2>&1111 }112 113 is_dry_run() {114 if [ -z "$DRY_RUN" ]; then115 return 1116 else117 return 0118 fi119 }120 121 deprecation_notice() {122 distro=$1123 date=$2124 echo125 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 echo129 sleep 10130 }131 132 get_distribution() {133 lsb_dist=""134 # Every system that we officially support has /etc/os-release135 if [ -r /etc/os-release ]; then136 lsb_dist="$(. /etc/os-release && echo "$ID")"137 fi138 # Returning an empty string here should be alright since the139 # case statements don't act unless you provide an actual value140 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; then147 (set -x; $sh_c "echo \"$backports\" >> /etc/apt/sources.list")148 fi149 }150 151 echo_docker_as_nonroot() {152 if is_dry_run; then153 return154 fi155 if command_exists docker && [ -e /var/run/docker.sock ]; then156 (157 set -x158 $sh_c 'docker version'159 ) || true160 fi161 your_user=your-user162 [ "$user" != 'root' ] && your_user="$user"163 # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output164 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 echo167 echo " sudo usermod -aG docker $your_user"168 echo169 echo "Remember that you will have to log out and back in for this to take effect!"170 echo171 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 distro180 check_forked() {181 182 # Check for lsb_release command existence, it usually exists in forked distros183 if command_exists lsb_release; then184 # Check if the `-u` option is supported185 set +e186 lsb_release -a -u > /dev/null 2>&1187 lsb_release_exit_code=$?188 set -e189 190 # Check if the command has exited successfully, it means we're in a forked distro191 if [ "$lsb_release_exit_code" = "0" ]; then192 # Print info about current distro193 cat <<-EOF194 You're using '$lsb_dist' version '$dist_version'.195 EOF196 197 # Get the upstream release info198 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 distro202 cat <<-EOF203 Upstream release is '$lsb_dist' version '$dist_version'.204 EOF205 else206 if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then207 if [ "$lsb_dist" = "osmc" ]; then208 # OSMC runs Raspbian209 lsb_dist=raspbian210 else211 # We're Debian and don't even know it!212 lsb_dist=debian213 fi214 dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"215 case "$dist_version" in216 9)217 dist_version="stretch"218 ;;219 8|'Kali Linux 2')220 dist_version="jessie"221 ;;222 7)223 dist_version="wheezy"224 ;;225 esac226 fi227 fi228 fi229 }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 echo241 echo242 echo " WARNING: $1 is now only supported by Docker EE"243 echo " Check https://store.docker.com for information on Docker EE"244 echo245 echo246 }247 248 do_install() {249 echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"250 251 if command_exists docker; then252 docker_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"253 MAJOR_W=1254 MINOR_W=10255 256 semverParse "$docker_version"257 258 shouldWarn=0259 if [ "$major" -lt "$MAJOR_W" ]; then260 shouldWarn=1261 fi262 263 if [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; then264 shouldWarn=1265 fi266 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 is271 why we're displaying this warning and provide the opportunity to cancel the272 installation.273 274 If you installed the current Docker package using this script and are using it275 EOF276 277 if [ $shouldWarn -eq 1 ]; then278 cat >&2 <<-'EOF'279 again to update Docker, we urge you to migrate your image store before upgrading280 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-migration284 EOF285 else286 cat >&2 <<-'EOF'287 again to update Docker, you can safely ignore this message.288 EOF289 fi290 291 cat >&2 <<-'EOF'292 293 You may press Ctrl+C now to abort this script.294 EOF295 ( set -x; sleep 20 )296 fi297 298 user="$(id -un 2>/dev/null || true)"299 300 sh_c='sh -c'301 if [ "$user" != 'root' ]; then302 if command_exists sudo; then303 sh_c='sudo -E sh -c'304 elif command_exists su; then305 sh_c='su -c'306 else307 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 EOF311 exit 1312 fi313 fi314 315 if is_dry_run; then316 sh_c="echo"317 fi318 319 # perform some very rudimentary platform detection320 lsb_dist=$( get_distribution )321 lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"322 323 case "$lsb_dist" in324 325 ubuntu)326 if command_exists lsb_release; then327 dist_version="$(lsb_release --codename | cut -f2)"328 fi329 if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then330 dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"331 fi332 ;;333 334 debian|raspbian)335 dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"336 case "$dist_version" in337 9)338 dist_version="stretch"339 ;;340 8)341 dist_version="jessie"342 ;;343 7)344 dist_version="wheezy"345 ;;346 esac347 ;;348 349 centos)350 if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then351 dist_version="$(. /etc/os-release && echo "$VERSION_ID")"352 fi353 ;;354 355 rhel|ol|sles)356 ee_notice "$lsb_dist"357 exit 1358 ;;359 360 *)361 if command_exists lsb_release; then362 dist_version="$(lsb_release --release | cut -f2)"363 fi364 if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then365 dist_version="$(. /etc/os-release && echo "$VERSION_ID")"366 fi367 ;;368 369 esac370 371 # Check if this is a forked Linux distro372 check_forked373 374 # Check if we actually support this configuration375 if ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; then376 cat >&2 <<-'EOF'377 378 Either your platform is not easily detectable or is not supported by this379 installer script.380 Please visit the following URL for more detailed installation instructions:381 382 https://docs.docker.com/engine/installation/383 384 EOF385 exit 1386 fi387 388 # Run setup for each distro accordingly389 case "$lsb_dist" in390 ubuntu|debian|raspbian)391 pre_reqs="apt-transport-https ca-certificates curl"392 if [ "$lsb_dist" = "debian" ]; then393 if [ "$dist_version" = "wheezy" ]; then394 add_debian_backport_repo "$dist_version"395 fi396 # libseccomp2 does not exist for debian jessie main repos for aarch64397 if [ "$(uname -m)" = "aarch64" ] && [ "$dist_version" = "jessie" ]; then398 add_debian_backport_repo "$dist_version"399 fi400 fi401 402 # TODO: August 31, 2018 delete from here,403 if [ "$lsb_dist" = "ubuntu" ] && [ "$dist_version" = "artful" ]; then404 deprecation_notice "$lsb_dist $dist_version" "August 31, 2018"405 fi406 # TODO: August 31, 2018 delete to here,407 408 if ! command -v gpg > /dev/null; then409 pre_reqs="$pre_reqs gnupg"410 fi411 apt_repo="deb [arch=$(dpkg --print-architecture)] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"412 (413 if ! is_dry_run; then414 set -x415 fi416 $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" ]; then421 $sh_c 'sed -i "/deb-src.*download\.docker/d" /etc/apt/sources.list.d/docker.list'422 fi423 $sh_c 'apt-get update -qq >/dev/null'424 )425 pkg_version=""426 if [ ! -z "$VERSION" ]; then427 if is_dry_run; then428 echo "# WARNING: VERSION pinning is not supported in DRY_RUN"429 else430 # Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel431 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" ]; then437 echo438 echo "ERROR: '$VERSION' not found amongst apt-cache madison results"439 echo440 exit 1441 fi442 pkg_version="=$pkg_version"443 fi444 fi445 (446 if ! is_dry_run; then447 set -x448 fi449 $sh_c "apt-get install -y -qq --no-install-recommends docker-ce$pkg_version >/dev/null"450 )451 echo_docker_as_nonroot452 exit 0453 ;;454 centos|fedora)455 yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/$REPO_FILE"456 if ! curl -Ifs "$yum_repo" > /dev/null; then457 echo "Error: Unable to curl repository file $yum_repo, is it valid?"458 exit 1459 fi460 if [ "$lsb_dist" = "fedora" ]; then461 if [ "$dist_version" -lt "26" ]; then462 echo "Error: Only Fedora >=26 are supported"463 exit 1464 fi465 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 else472 pkg_manager="yum"473 config_manager="yum-config-manager"474 enable_channel_flag="--enable"475 pre_reqs="yum-utils"476 pkg_suffix="el"477 fi478 (479 if ! is_dry_run; then480 set -x481 fi482 $sh_c "$pkg_manager install -y -q $pre_reqs"483 $sh_c "$config_manager --add-repo $yum_repo"484 485 if [ "$CHANNEL" != "stable" ]; then486 $sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL"487 fi488 $sh_c "$pkg_manager makecache"489 )490 pkg_version=""491 if [ ! -z "$VERSION" ]; then492 if is_dry_run; then493 echo "# WARNING: VERSION pinning is not supported in DRY_RUN"494 else495 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" ]; then501 echo502 echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"503 echo504 exit 1505 fi506 # Cut out the epoch and prefix with a '-'507 pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"508 fi509 fi510 (511 if ! is_dry_run; then512 set -x513 fi514 $sh_c "$pkg_manager install -y -q docker-ce$pkg_version"515 )516 echo_docker_as_nonroot517 exit 0518 ;;519 esac520 exit 1521 }522 523 # wrapped up in a function so that we have some protection against only getting524 # half the file during "curl | sh"525 do_install
1 chmod +x getdocker.sh 2 ./getdocker.sh -s docker --mirror Aliyun
getdocker.sh 文件内容在上个代码区域