install.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. #
  10. # Docker Maintainers:
  11. # To update this script on https://get.docker.com,
  12. # use hack/release.sh during a normal release,
  13. # or the following one-liner for script hotfixes:
  14. # s3cmd put --acl-public -P hack/install.sh s3://get.docker.com/index
  15. #
  16. url='https://get.docker.com/'
  17. command_exists() {
  18. command -v "$@" > /dev/null 2>&1
  19. }
  20. case "$(uname -m)" in
  21. *64)
  22. ;;
  23. *)
  24. echo >&2 'Error: you are not using a 64bit platform.'
  25. echo >&2 'Docker currently only supports 64bit platforms.'
  26. exit 1
  27. ;;
  28. esac
  29. if command_exists docker || command_exists lxc-docker; then
  30. echo >&2 'Warning: "docker" or "lxc-docker" command appears to already exist.'
  31. echo >&2 'Please ensure that you do not already have docker installed.'
  32. echo >&2 'You may press Ctrl+C now to abort this process and rectify this situation.'
  33. ( set -x; sleep 20 )
  34. fi
  35. user="$(id -un 2>/dev/null || true)"
  36. sh_c='sh -c'
  37. if [ "$user" != 'root' ]; then
  38. if command_exists sudo; then
  39. sh_c='sudo -E sh -c'
  40. elif command_exists su; then
  41. sh_c='su -c'
  42. else
  43. echo >&2 'Error: this installer needs the ability to run commands as root.'
  44. echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
  45. exit 1
  46. fi
  47. fi
  48. curl=''
  49. if command_exists curl; then
  50. curl='curl -sSL'
  51. elif command_exists wget; then
  52. curl='wget -qO-'
  53. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  54. curl='busybox wget -qO-'
  55. fi
  56. # perform some very rudimentary platform detection
  57. lsb_dist=''
  58. if command_exists lsb_release; then
  59. lsb_dist="$(lsb_release -si)"
  60. fi
  61. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  62. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  63. fi
  64. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  65. lsb_dist='debian'
  66. fi
  67. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  68. lsb_dist='fedora'
  69. fi
  70. if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
  71. lsb_dist="$(. /etc/os-release && echo "$ID")"
  72. fi
  73. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  74. case "$lsb_dist" in
  75. amzn|fedora)
  76. if [ "$lsb_dist" = 'amzn' ]; then
  77. (
  78. set -x
  79. $sh_c 'sleep 3; yum -y -q install docker'
  80. )
  81. else
  82. (
  83. set -x
  84. $sh_c 'sleep 3; yum -y -q install docker-io'
  85. )
  86. fi
  87. if command_exists docker && [ -e /var/run/docker.sock ]; then
  88. (
  89. set -x
  90. $sh_c 'docker version'
  91. ) || true
  92. fi
  93. your_user=your-user
  94. [ "$user" != 'root' ] && your_user="$user"
  95. echo
  96. echo 'If you would like to use Docker as a non-root user, you should now consider'
  97. echo 'adding your user to the "docker" group with something like:'
  98. echo
  99. echo ' sudo usermod -aG docker' $your_user
  100. echo
  101. echo 'Remember that you will have to log out and back in for this to take effect!'
  102. echo
  103. exit 0
  104. ;;
  105. ubuntu|debian|linuxmint)
  106. export DEBIAN_FRONTEND=noninteractive
  107. did_apt_get_update=
  108. apt_get_update() {
  109. if [ -z "$did_apt_get_update" ]; then
  110. ( set -x; $sh_c 'sleep 3; apt-get update' )
  111. did_apt_get_update=1
  112. fi
  113. }
  114. # aufs is preferred over devicemapper; try to ensure the driver is available.
  115. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  116. kern_extras="linux-image-extra-$(uname -r)"
  117. apt_get_update
  118. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  119. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  120. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  121. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  122. ( set -x; sleep 10 )
  123. fi
  124. fi
  125. # install apparmor utils if they're missing and apparmor is enabled in the kernel
  126. # otherwise Docker will fail to start
  127. if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
  128. if command -v apparmor_parser &> /dev/null; then
  129. echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
  130. else
  131. echo 'apparmor is enabled in the kernel, but apparmor_parser missing'
  132. apt_get_update
  133. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
  134. fi
  135. fi
  136. if [ ! -e /usr/lib/apt/methods/https ]; then
  137. apt_get_update
  138. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https' )
  139. fi
  140. if [ -z "$curl" ]; then
  141. apt_get_update
  142. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl' )
  143. curl='curl -sSL'
  144. fi
  145. (
  146. set -x
  147. if [ "https://get.docker.com/" = "$url" ]; then
  148. $sh_c "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9"
  149. elif [ "https://test.docker.com/" = "$url" ]; then
  150. $sh_c "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 740B314AE3941731B942C66ADF4FD13717AAD7D6"
  151. else
  152. $sh_c "$curl ${url}gpg | apt-key add -"
  153. fi
  154. $sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list"
  155. $sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker'
  156. )
  157. if command_exists docker && [ -e /var/run/docker.sock ]; then
  158. (
  159. set -x
  160. $sh_c 'docker version'
  161. ) || true
  162. fi
  163. your_user=your-user
  164. [ "$user" != 'root' ] && your_user="$user"
  165. echo
  166. echo 'If you would like to use Docker as a non-root user, you should now consider'
  167. echo 'adding your user to the "docker" group with something like:'
  168. echo
  169. echo ' sudo usermod -aG docker' $your_user
  170. echo
  171. echo 'Remember that you will have to log out and back in for this to take effect!'
  172. echo
  173. exit 0
  174. ;;
  175. gentoo)
  176. if [ "$url" = "https://test.docker.com/" ]; then
  177. echo >&2
  178. echo >&2 ' You appear to be trying to install the latest nightly build in Gentoo.'
  179. echo >&2 ' The portage tree should contain the latest stable release of Docker, but'
  180. echo >&2 ' if you want something more recent, you can always use the live ebuild'
  181. echo >&2 ' provided in the "docker" overlay available via layman. For more'
  182. echo >&2 ' instructions, please see the following URL:'
  183. echo >&2 ' https://github.com/tianon/docker-overlay#using-this-overlay'
  184. echo >&2 ' After adding the "docker" overlay, you should be able to:'
  185. echo >&2 ' emerge -av =app-emulation/docker-9999'
  186. echo >&2
  187. exit 1
  188. fi
  189. (
  190. set -x
  191. $sh_c 'sleep 3; emerge app-emulation/docker'
  192. )
  193. exit 0
  194. ;;
  195. esac
  196. cat >&2 <<'EOF'
  197. Either your platform is not easily detectable, is not supported by this
  198. installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
  199. a package for Docker. Please visit the following URL for more detailed
  200. installation instructions:
  201. https://docs.docker.com/en/latest/installation/
  202. EOF
  203. exit 1