Install docker script (Code tutorial) and docker script code tutorial

Source: Internet
Author: User
Tags kali linux

Install docker script (Code tutorial) and docker script code tutorial

Install docker script (Code tutorial)

#!/bin/shset -e# This script is meant for quick & easy install via:#   $ curl -fsSL get.docker.com -o get-docker.sh#   $ sh get-docker.sh## For test builds (ie. release candidates):#   $ curl -fsSL test.docker.com -o test-docker.sh#   $ sh test-docker.sh## NOTE: Make sure to verify the contents of the script#       you downloaded matches the contents of install.sh#       located at https://github.com/docker/docker-install#       before executing.## Git commit from https://github.com/docker/docker-install when# the script was uploaded (Should only be modified by upload job):SCRIPT_COMMIT_SHA=1d31602# This value will automatically get changed for:#   * edge#   * test#   * experimentalDEFAULT_CHANNEL_VALUE="edge"if [ -z "$CHANNEL" ]; thenCHANNEL=$DEFAULT_CHANNEL_VALUEfiDOWNLOAD_URL="https://download.docker.com"SUPPORT_MAP="x86_64-centos-7x86_64-fedora-24x86_64-fedora-25x86_64-fedora-26x86_64-fedora-27x86_64-debian-wheezyx86_64-debian-jessiex86_64-debian-stretchx86_64-debian-busterx86_64-ubuntu-trustyx86_64-ubuntu-xenialx86_64-ubuntu-zestyx86_64-ubuntu-artfuls390x-ubuntu-xenials390x-ubuntu-zestys390x-ubuntu-artfulppc64le-ubuntu-xenialppc64le-ubuntu-zestyppc64le-ubuntu-artfulaarch64-ubuntu-xenialaarch64-ubuntu-zestyaarch64-debian-jessieaarch64-debian-stretcharmv6l-raspbian-jessiearmv7l-raspbian-jessiearmv6l-raspbian-stretcharmv7l-raspbian-stretcharmv7l-debian-jessiearmv7l-debian-stretcharmv7l-debian-busterarmv7l-ubuntu-trustyarmv7l-ubuntu-xenialarmv7l-ubuntu-zestyarmv7l-ubuntu-artful"mirror=''DRY_RUN=${DRY_RUN:-}while [ $# -gt 0 ]; docase "$1" in--mirror)mirror="$2"shift;;--dry-run)DRY_RUN=1;;--*)echo "Illegal option $1";;esacshift $(( $# > 0 ? 1 : 0 ))donecase "$mirror" inAliyun)DOWNLOAD_URL="https://mirrors.aliyun.com/docker-ce";;AzureChinaCloud)DOWNLOAD_URL="https://mirror.azure.cn/docker-ce";;esaccommand_exists() {command -v "$@" > /dev/null 2>&1}is_dry_run() {if [ -z "$DRY_RUN" ]; thenreturn 1elsereturn 0fi}get_distribution() {lsb_dist=""# Every system that we officially support has /etc/os-releaseif [ -r /etc/os-release ]; thenlsb_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 valueecho "$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; thenreturnfiif command_exists docker && [ -e /var/run/docker.sock ]; then(set -x$sh_c 'docker version') || truefiyour_user=your-user[ "$user" != 'root' ] && your_user="$user"# intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the outputecho "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:"echoecho "  sudo usermod -aG docker $your_user"echoecho "Remember that you will have to log out and back in for this to take effect!"echoecho "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 if this is a forked Linux distrocheck_forked() {# Check for lsb_release command existence, it usually exists in forked distrosif command_exists lsb_release; then# Check if the `-u` option is supportedset +elsb_release -a -u > /dev/null 2>&1lsb_release_exit_code=$?set -e# Check if the command has exited successfully, it means we're in a forked distroif [ "$lsb_release_exit_code" = "0" ]; then# Print info about current distrocat <<-EOFYou're using '$lsb_dist' version '$dist_version'.EOF# Get the upstream release infolsb_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:]')# Print info about upstream distrocat <<-EOFUpstream release is '$lsb_dist' version '$dist_version'.EOFelseif [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then# We're Debian and don't even know it!lsb_dist=debiandist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"case "$dist_version" in9)dist_version="stretch";;8|'Kali Linux 2')dist_version="jessie";;7)dist_version="wheezy";;esacfififi}semverParse() {major="${1%%.*}"minor="${1#$major.}"minor="${minor%%.*}"patch="${1#$major.$minor.}"patch="${patch%%[-.]*}"}ee_notice() {echoechoecho "  WARNING: $1 is now only supported by Docker EE"echo "           Check https://store.docker.com for information on Docker EE"echoecho}do_install() {echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"if command_exists docker; thenversion="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"MAJOR_W=1MINOR_W=10semverParse "$version"shouldWarn=0if [ "$major" -lt "$MAJOR_W" ]; thenshouldWarn=1fiif [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; thenshouldWarn=1ficat >&2 <<-'EOF'Warning: the "docker" command appears to already exist on this system.If you already have Docker installed, this script can cause trouble, which iswhy we're displaying this warning and provide the opportunity to cancel theinstallation.If you installed the current Docker package using this script and are using itEOFif [ $shouldWarn -eq 1 ]; thencat >&2 <<-'EOF'again to update Docker, we urge you to migrate your image store before upgradingto v1.10+.You can find instructions for this here:https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migrationEOFelsecat >&2 <<-'EOF'again to update Docker, you can safely ignore this message.EOFficat >&2 <<-'EOF'You may press Ctrl+C now to abort this script.EOF( set -x; sleep 20 )fiuser="$(id -un 2>/dev/null || true)"sh_c='sh -c'if [ "$user" != 'root' ]; thenif command_exists sudo; thensh_c='sudo -E sh -c'elif command_exists su; thensh_c='su -c'elsecat >&2 <<-'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.EOFexit 1fifiif is_dry_run; thensh_c="echo"fi# perform some very rudimentary platform detectionlsb_dist=$( get_distribution )lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"case "$lsb_dist" inubuntu)if command_exists lsb_release; thendist_version="$(lsb_release --codename | cut -f2)"fiif [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; thendist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"fi;;debian|raspbian)dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"case "$dist_version" in9)dist_version="stretch";;8)dist_version="jessie";;7)dist_version="wheezy";;esac;;centos)if [ -z "$dist_version" ] && [ -r /etc/os-release ]; thendist_version="$(. /etc/os-release && echo "$VERSION_ID")"fi;;rhel|ol|sles)ee_notice "$lsb_dist"exit 1;;*)if command_exists lsb_release; thendist_version="$(lsb_release --release | cut -f2)"fiif [ -z "$dist_version" ] && [ -r /etc/os-release ]; thendist_version="$(. /etc/os-release && echo "$VERSION_ID")"fi;;esac# Check if this is a forked Linux distrocheck_forked# Check if we actually support this configurationif ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; thencat >&2 <<-'EOF'Either your platform is not easily detectable or is not supported by thisinstaller script.Please visit the following URL for more detailed installation instructions:https://docs.docker.com/engine/installation/EOFexit 1fi# Run setup for each distro accordinglycase "$lsb_dist" inubuntu|debian|raspbian)pre_reqs="apt-transport-https ca-certificates curl"if [ "$lsb_dist" = "debian" ]; thenif [ "$dist_version" = "wheezy" ]; thenadd_debian_backport_repo "$dist_version"fi# libseccomp2 does not exist for debian jessie main repos for aarch64if [ "$(uname -m)" = "aarch64" ] && [ "$dist_version" = "jessie" ]; thenadd_debian_backport_repo "$dist_version"fifiif ! command -v gpg > /dev/null; thenpre_reqs="$pre_reqs gnupg"fiapt_repo="deb [arch=$(dpkg --print-architecture)] $DOWNLOAD_URL/linux/$lsb_dist $dist_version $CHANNEL"(if ! is_dry_run; thenset -xfi$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'$sh_c 'apt-get install -y -qq --no-install-recommends docker-ce >/dev/null')echo_docker_as_nonrootexit 0;;centos|fedora)yum_repo="$DOWNLOAD_URL/linux/$lsb_dist/docker-ce.repo"if [ "$lsb_dist" = "fedora" ]; thenif [ "$dist_version" = "24" ]; thenechoecho "Warning: Fedora 24 has reached EOL"echo "         Support for Fedora 24 for this installation script will be removed on October 1, 2017"echosleep 10fiif [ "$dist_version" -lt "24" ]; thenecho "Error: Only Fedora >=24 are supported"exit 1fipkg_manager="dnf"config_manager="dnf config-manager"enable_channel_flag="--set-enabled"pre_reqs="dnf-plugins-core"elsepkg_manager="yum"config_manager="yum-config-manager"enable_channel_flag="--enable"pre_reqs="yum-utils"fi(if ! is_dry_run; thenset -xfi$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"$sh_c "$pkg_manager install -y -q docker-ce")echo_docker_as_nonrootexit 0;;esacexit 1}# wrapped up in a function so that we have some protection against only getting# half the file during "curl | sh"do_install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.