install.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. #!/bin/sh
  2. set -e
  3. #
  4. # This script is meant for quick & easy install via:
  5. # 'curl -sSL https://get.docker.com/ | sh'
  6. # or:
  7. # 'wget -qO- https://get.docker.com/ | sh'
  8. #
  9. # For test builds (ie. release candidates):
  10. # 'curl -fsSL https://test.docker.com/ | sh'
  11. # or:
  12. # 'wget -qO- https://test.docker.com/ | sh'
  13. #
  14. # For experimental builds:
  15. # 'curl -fsSL https://experimental.docker.com/ | sh'
  16. # or:
  17. # 'wget -qO- https://experimental.docker.com/ | sh'
  18. #
  19. # Docker Maintainers:
  20. # To update this script on https://get.docker.com,
  21. # use hack/release.sh during a normal release,
  22. # or the following one-liner for script hotfixes:
  23. # aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index
  24. #
  25. url="https://get.docker.com/"
  26. apt_url="https://apt.dockerproject.org"
  27. yum_url="https://yum.dockerproject.org"
  28. gpg_fingerprint="58118E89F3A912897C070ADBF76221572C52609D"
  29. key_servers="
  30. ha.pool.sks-keyservers.net
  31. pgp.mit.edu
  32. keyserver.ubuntu.com
  33. "
  34. command_exists() {
  35. command -v "$@" > /dev/null 2>&1
  36. }
  37. echo_docker_as_nonroot() {
  38. if command_exists docker && [ -e /var/run/docker.sock ]; then
  39. (
  40. set -x
  41. $sh_c 'docker version'
  42. ) || true
  43. fi
  44. your_user=your-user
  45. [ "$user" != 'root' ] && your_user="$user"
  46. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
  47. cat <<-EOF
  48. If you would like to use Docker as a non-root user, you should now consider
  49. adding your user to the "docker" group with something like:
  50. sudo usermod -aG docker $your_user
  51. Remember that you will have to log out and back in for this to take effect!
  52. EOF
  53. }
  54. # Check if this is a forked Linux distro
  55. check_forked() {
  56. # Check for lsb_release command existence, it usually exists in forked distros
  57. if command_exists lsb_release; then
  58. # Check if the `-u` option is supported
  59. set +e
  60. lsb_release -a -u > /dev/null 2>&1
  61. lsb_release_exit_code=$?
  62. set -e
  63. # Check if the command has exited successfully, it means we're in a forked distro
  64. if [ "$lsb_release_exit_code" = "0" ]; then
  65. # Print info about current distro
  66. cat <<-EOF
  67. You're using '$lsb_dist' version '$dist_version'.
  68. EOF
  69. # Get the upstream release info
  70. lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  71. dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]')
  72. # Print info about upstream distro
  73. cat <<-EOF
  74. Upstream release is '$lsb_dist' version '$dist_version'.
  75. EOF
  76. else
  77. if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
  78. # We're Debian and don't even know it!
  79. lsb_dist=debian
  80. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  81. case "$dist_version" in
  82. 8|'Kali Linux 2')
  83. dist_version="jessie"
  84. ;;
  85. 7)
  86. dist_version="wheezy"
  87. ;;
  88. esac
  89. fi
  90. fi
  91. fi
  92. }
  93. rpm_import_repository_key() {
  94. local key=$1; shift
  95. local tmpdir=$(mktemp -d)
  96. chmod 600 "$tmpdir"
  97. for key_server in $key_servers ; do
  98. gpg --homedir "$tmpdir" --keyserver "$key_server" --recv-keys "$key" && break
  99. done
  100. gpg --homedir "$tmpdir" -k "$key" >/dev/null
  101. gpg --homedir "$tmpdir" --export --armor "$key" > "$tmpdir"/repo.key
  102. rpm --import "$tmpdir"/repo.key
  103. rm -rf "$tmpdir"
  104. }
  105. semverParse() {
  106. major="${1%%.*}"
  107. minor="${1#$major.}"
  108. minor="${minor%%.*}"
  109. patch="${1#$major.$minor.}"
  110. patch="${patch%%[-.]*}"
  111. }
  112. do_install() {
  113. case "$(uname -m)" in
  114. *64)
  115. ;;
  116. armv6l|armv7l)
  117. ;;
  118. *)
  119. cat >&2 <<-'EOF'
  120. Error: you are not using a 64bit platform or a Raspberry Pi (armv6l/armv7l).
  121. Docker currently only supports 64bit platforms or a Raspberry Pi (armv6l/armv7l).
  122. EOF
  123. exit 1
  124. ;;
  125. esac
  126. if command_exists docker; then
  127. version="$(docker -v | awk -F '[ ,]+' '{ print $3 }')"
  128. MAJOR_W=1
  129. MINOR_W=10
  130. semverParse $version
  131. shouldWarn=0
  132. if [ $major -lt $MAJOR_W ]; then
  133. shouldWarn=1
  134. fi
  135. if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then
  136. shouldWarn=1
  137. fi
  138. cat >&2 <<-'EOF'
  139. Warning: the "docker" command appears to already exist on this system.
  140. If you already have Docker installed, this script can cause trouble, which is
  141. why we're displaying this warning and provide the opportunity to cancel the
  142. installation.
  143. If you installed the current Docker package using this script and are using it
  144. EOF
  145. if [ $shouldWarn -eq 1 ]; then
  146. cat >&2 <<-'EOF'
  147. again to update Docker, we urge you to migrate your image store before upgrading
  148. to v1.10+.
  149. You can find instructions for this here:
  150. https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration
  151. EOF
  152. else
  153. cat >&2 <<-'EOF'
  154. again to update Docker, you can safely ignore this message.
  155. EOF
  156. fi
  157. cat >&2 <<-'EOF'
  158. You may press Ctrl+C now to abort this script.
  159. EOF
  160. ( set -x; sleep 20 )
  161. fi
  162. user="$(id -un 2>/dev/null || true)"
  163. sh_c='sh -c'
  164. if [ "$user" != 'root' ]; then
  165. if command_exists sudo; then
  166. sh_c='sudo -E sh -c'
  167. elif command_exists su; then
  168. sh_c='su -c'
  169. else
  170. cat >&2 <<-'EOF'
  171. Error: this installer needs the ability to run commands as root.
  172. We are unable to find either "sudo" or "su" available to make this happen.
  173. EOF
  174. exit 1
  175. fi
  176. fi
  177. curl=''
  178. if command_exists curl; then
  179. curl='curl -sSL'
  180. elif command_exists wget; then
  181. curl='wget -qO-'
  182. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  183. curl='busybox wget -qO-'
  184. fi
  185. # check to see which repo they are trying to install from
  186. if [ -z "$repo" ]; then
  187. repo='main'
  188. if [ "https://test.docker.com/" = "$url" ]; then
  189. repo='testing'
  190. elif [ "https://experimental.docker.com/" = "$url" ]; then
  191. repo='experimental'
  192. fi
  193. fi
  194. # perform some very rudimentary platform detection
  195. lsb_dist=''
  196. dist_version=''
  197. if command_exists lsb_release; then
  198. lsb_dist="$(lsb_release -si)"
  199. fi
  200. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  201. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  202. fi
  203. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  204. lsb_dist='debian'
  205. fi
  206. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  207. lsb_dist='fedora'
  208. fi
  209. if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then
  210. lsb_dist='oracleserver'
  211. fi
  212. if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then
  213. lsb_dist='centos'
  214. fi
  215. if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then
  216. lsb_dist='redhat'
  217. fi
  218. if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
  219. lsb_dist="$(. /etc/os-release && echo "$ID")"
  220. fi
  221. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  222. # Special case redhatenterpriseserver
  223. if [ "${lsb_dist}" = "redhatenterpriseserver" ]; then
  224. # Set it to redhat, it will be changed to centos below anyways
  225. lsb_dist='redhat'
  226. fi
  227. case "$lsb_dist" in
  228. ubuntu)
  229. if command_exists lsb_release; then
  230. dist_version="$(lsb_release --codename | cut -f2)"
  231. fi
  232. if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
  233. dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
  234. fi
  235. ;;
  236. debian|raspbian)
  237. dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
  238. case "$dist_version" in
  239. 8)
  240. dist_version="jessie"
  241. ;;
  242. 7)
  243. dist_version="wheezy"
  244. ;;
  245. esac
  246. ;;
  247. oracleserver)
  248. # need to switch lsb_dist to match yum repo URL
  249. lsb_dist="oraclelinux"
  250. dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')"
  251. ;;
  252. fedora|centos|redhat)
  253. dist_version="$(rpm -q --whatprovides ${lsb_dist}-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//' | sort | tail -1)"
  254. ;;
  255. *)
  256. if command_exists lsb_release; then
  257. dist_version="$(lsb_release --codename | cut -f2)"
  258. fi
  259. if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
  260. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  261. fi
  262. ;;
  263. esac
  264. # Check if this is a forked Linux distro
  265. check_forked
  266. # Run setup for each distro accordingly
  267. case "$lsb_dist" in
  268. amzn)
  269. (
  270. set -x
  271. $sh_c 'sleep 3; yum -y -q install docker'
  272. )
  273. echo_docker_as_nonroot
  274. exit 0
  275. ;;
  276. 'opensuse project'|opensuse)
  277. echo 'Going to perform the following operations:'
  278. if [ "$repo" != 'main' ]; then
  279. echo ' * add repository obs://Virtualization:containers'
  280. fi
  281. echo ' * install Docker'
  282. $sh_c 'echo "Press CTRL-C to abort"; sleep 3'
  283. if [ "$repo" != 'main' ]; then
  284. # install experimental packages from OBS://Virtualization:containers
  285. (
  286. set -x
  287. zypper -n ar -f obs://Virtualization:containers Virtualization:containers
  288. rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
  289. )
  290. fi
  291. (
  292. set -x
  293. zypper -n install docker
  294. )
  295. echo_docker_as_nonroot
  296. exit 0
  297. ;;
  298. 'suse linux'|sle[sd])
  299. echo 'Going to perform the following operations:'
  300. if [ "$repo" != 'main' ]; then
  301. echo ' * add repository obs://Virtualization:containers'
  302. echo ' * install experimental Docker using packages NOT supported by SUSE'
  303. else
  304. echo ' * add the "Containers" module'
  305. echo ' * install Docker using packages supported by SUSE'
  306. fi
  307. $sh_c 'echo "Press CTRL-C to abort"; sleep 3'
  308. if [ "$repo" != 'main' ]; then
  309. # install experimental packages from OBS://Virtualization:containers
  310. echo >&2 'Warning: installing experimental packages from OBS, these packages are NOT supported by SUSE'
  311. (
  312. set -x
  313. zypper -n ar -f obs://Virtualization:containers/SLE_12 Virtualization:containers
  314. rpm_import_repository_key 55A0B34D49501BB7CA474F5AA193FBB572174FC2
  315. )
  316. else
  317. # Add the containers module
  318. # Note well-1: the SLE machine must already be registered against SUSE Customer Center
  319. # Note well-2: the `-r ""` is required to workaround a known issue of SUSEConnect
  320. (
  321. set -x
  322. SUSEConnect -p sle-module-containers/12/x86_64 -r ""
  323. )
  324. fi
  325. (
  326. set -x
  327. zypper -n install docker
  328. )
  329. echo_docker_as_nonroot
  330. exit 0
  331. ;;
  332. ubuntu|debian|raspbian)
  333. export DEBIAN_FRONTEND=noninteractive
  334. did_apt_get_update=
  335. apt_get_update() {
  336. if [ -z "$did_apt_get_update" ]; then
  337. ( set -x; $sh_c 'sleep 3; apt-get update' )
  338. did_apt_get_update=1
  339. fi
  340. }
  341. if [ "$lsb_dist" = "raspbian" ]; then
  342. # Create Raspbian specific systemd drop-in file, use overlay by default
  343. ( set -x; $sh_c "mkdir -p /etc/systemd/system/docker.service.d" )
  344. ( set -x; $sh_c "echo '[Service]\nExecStart=\nExecStart=/usr/bin/dockerd --storage-driver overlay -H fd://' > /etc/systemd/system/docker.service.d/overlay.conf" )
  345. else
  346. # aufs is preferred over devicemapper; try to ensure the driver is available.
  347. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  348. if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then
  349. kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
  350. apt_get_update
  351. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  352. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  353. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  354. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  355. ( set -x; sleep 10 )
  356. fi
  357. else
  358. echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
  359. echo >&2 ' package. We have no AUFS support. Consider installing the packages'
  360. echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
  361. ( set -x; sleep 10 )
  362. fi
  363. fi
  364. fi
  365. # install apparmor utils if they're missing and apparmor is enabled in the kernel
  366. # otherwise Docker will fail to start
  367. if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
  368. if command -v apparmor_parser >/dev/null 2>&1; then
  369. echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
  370. else
  371. echo 'apparmor is enabled in the kernel, but apparmor_parser is missing. Trying to install it..'
  372. apt_get_update
  373. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
  374. fi
  375. fi
  376. if [ ! -e /usr/lib/apt/methods/https ]; then
  377. apt_get_update
  378. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
  379. fi
  380. if [ -z "$curl" ]; then
  381. apt_get_update
  382. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
  383. curl='curl -sSL'
  384. fi
  385. (
  386. set -x
  387. for key_server in $key_servers ; do
  388. $sh_c "apt-key adv --keyserver hkp://${key_server}:80 --recv-keys ${gpg_fingerprint}" && break
  389. done
  390. $sh_c "apt-key adv -k ${gpg_fingerprint} >/dev/null"
  391. $sh_c "mkdir -p /etc/apt/sources.list.d"
  392. $sh_c "echo deb \[arch=$(dpkg --print-architecture)\] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
  393. $sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine'
  394. )
  395. echo_docker_as_nonroot
  396. exit 0
  397. ;;
  398. fedora|centos|redhat|oraclelinux)
  399. if [ "${lsb_dist}" = "redhat" ]; then
  400. # we use the centos repository for both redhat and centos releases
  401. lsb_dist='centos'
  402. fi
  403. $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
  404. [docker-${repo}-repo]
  405. name=Docker ${repo} Repository
  406. baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version}
  407. enabled=1
  408. gpgcheck=1
  409. gpgkey=${yum_url}/gpg
  410. EOF
  411. if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
  412. (
  413. set -x
  414. $sh_c 'sleep 3; dnf -y -q install docker-engine'
  415. )
  416. else
  417. (
  418. set -x
  419. $sh_c 'sleep 3; yum -y -q install docker-engine'
  420. )
  421. fi
  422. echo_docker_as_nonroot
  423. exit 0
  424. ;;
  425. gentoo)
  426. if [ "$url" = "https://test.docker.com/" ]; then
  427. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  428. cat >&2 <<-'EOF'
  429. You appear to be trying to install the latest nightly build in Gentoo.'
  430. The portage tree should contain the latest stable release of Docker, but'
  431. if you want something more recent, you can always use the live ebuild'
  432. provided in the "docker" overlay available via layman. For more'
  433. instructions, please see the following URL:'
  434. https://github.com/tianon/docker-overlay#using-this-overlay'
  435. After adding the "docker" overlay, you should be able to:'
  436. emerge -av =app-emulation/docker-9999'
  437. EOF
  438. exit 1
  439. fi
  440. (
  441. set -x
  442. $sh_c 'sleep 3; emerge app-emulation/docker'
  443. )
  444. exit 0
  445. ;;
  446. esac
  447. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  448. cat >&2 <<-'EOF'
  449. Either your platform is not easily detectable, is not supported by this
  450. installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
  451. a package for Docker. Please visit the following URL for more detailed
  452. installation instructions:
  453. https://docs.docker.com/engine/installation/
  454. EOF
  455. exit 1
  456. }
  457. # wrapped up in a function so that we have some protection against only getting
  458. # half the file during "curl | sh"
  459. do_install