install.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. echo_docker_as_nonroot() {
  21. your_user=your-user
  22. [ "$user" != 'root' ] && your_user="$user"
  23. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
  24. cat <<-EOF
  25. If you would like to use Docker as a non-root user, you should now consider
  26. adding your user to the "docker" group with something like:
  27. sudo usermod -aG docker $your_user
  28. Remember that you will have to log out and back in for this to take effect!
  29. EOF
  30. }
  31. do_install() {
  32. case "$(uname -m)" in
  33. *64)
  34. ;;
  35. *)
  36. cat >&2 <<-'EOF'
  37. Error: you are not using a 64bit platform.
  38. Docker currently only supports 64bit platforms.
  39. EOF
  40. exit 1
  41. ;;
  42. esac
  43. if command_exists docker; then
  44. cat >&2 <<-'EOF'
  45. Warning: the "docker" command appears to already exist on this system.
  46. If you already have Docker installed, this script can cause trouble, which is
  47. why we're displaying this warning and provide the opportunity to cancel the
  48. installation.
  49. If you installed the current Docker package using this script and are using it
  50. again to update Docker, you can safely ignore this message.
  51. You may press Ctrl+C now to abort this script.
  52. EOF
  53. ( set -x; sleep 20 )
  54. fi
  55. user="$(id -un 2>/dev/null || true)"
  56. sh_c='sh -c'
  57. if [ "$user" != 'root' ]; then
  58. if command_exists sudo; then
  59. sh_c='sudo -E sh -c'
  60. elif command_exists su; then
  61. sh_c='su -c'
  62. else
  63. cat >&2 <<-'EOF'
  64. Error: this installer needs the ability to run commands as root.
  65. We are unable to find either "sudo" or "su" available to make this happen.
  66. EOF
  67. exit 1
  68. fi
  69. fi
  70. curl=''
  71. if command_exists curl; then
  72. curl='curl -sSL'
  73. elif command_exists wget; then
  74. curl='wget -qO-'
  75. elif command_exists busybox && busybox --list-modules | grep -q wget; then
  76. curl='busybox wget -qO-'
  77. fi
  78. # perform some very rudimentary platform detection
  79. lsb_dist=''
  80. if command_exists lsb_release; then
  81. lsb_dist="$(lsb_release -si)"
  82. fi
  83. if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
  84. lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
  85. fi
  86. if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
  87. lsb_dist='debian'
  88. fi
  89. if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then
  90. lsb_dist='fedora'
  91. fi
  92. if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
  93. lsb_dist="$(. /etc/os-release && echo "$ID")"
  94. fi
  95. lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
  96. case "$lsb_dist" in
  97. amzn|fedora|centos)
  98. if [ "$lsb_dist" = 'amzn' ]; then
  99. (
  100. set -x
  101. $sh_c 'sleep 3; yum -y -q install docker'
  102. )
  103. else
  104. (
  105. set -x
  106. $sh_c 'sleep 3; yum -y -q install docker-io'
  107. )
  108. fi
  109. if command_exists docker && [ -e /var/run/docker.sock ]; then
  110. (
  111. set -x
  112. $sh_c 'docker version'
  113. ) || true
  114. fi
  115. echo_docker_as_nonroot
  116. exit 0
  117. ;;
  118. 'opensuse project'|opensuse|'suse linux'|sled)
  119. (
  120. set -x
  121. $sh_c 'sleep 3; zypper -n install docker'
  122. )
  123. if command_exists docker && [ -e /var/run/docker.sock ]; then
  124. (
  125. set -x
  126. $sh_c 'docker version'
  127. ) || true
  128. fi
  129. echo_docker_as_nonroot
  130. exit 0
  131. ;;
  132. ubuntu|debian|linuxmint|'elementary os'|kali)
  133. export DEBIAN_FRONTEND=noninteractive
  134. did_apt_get_update=
  135. apt_get_update() {
  136. if [ -z "$did_apt_get_update" ]; then
  137. ( set -x; $sh_c 'sleep 3; apt-get update' )
  138. did_apt_get_update=1
  139. fi
  140. }
  141. # aufs is preferred over devicemapper; try to ensure the driver is available.
  142. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  143. if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -q '^ii' 2>/dev/null; then
  144. kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
  145. apt_get_update
  146. ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
  147. if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
  148. echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
  149. echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!'
  150. ( set -x; sleep 10 )
  151. fi
  152. else
  153. echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
  154. echo >&2 ' package. We have no AUFS support. Consider installing the packages'
  155. echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
  156. ( set -x; sleep 10 )
  157. fi
  158. fi
  159. # install apparmor utils if they're missing and apparmor is enabled in the kernel
  160. # otherwise Docker will fail to start
  161. if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
  162. if command -v apparmor_parser &> /dev/null; then
  163. echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
  164. else
  165. echo 'apparmor is enabled in the kernel, but apparmor_parser missing'
  166. apt_get_update
  167. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
  168. fi
  169. fi
  170. if [ ! -e /usr/lib/apt/methods/https ]; then
  171. apt_get_update
  172. ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
  173. fi
  174. if [ -z "$curl" ]; then
  175. apt_get_update
  176. ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
  177. curl='curl -sSL'
  178. fi
  179. (
  180. set -x
  181. if [ "https://get.docker.com/" = "$url" ]; then
  182. $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9"
  183. elif [ "https://test.docker.com/" = "$url" ]; then
  184. $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 740B314AE3941731B942C66ADF4FD13717AAD7D6"
  185. elif [ "https://experimental.docker.com/" = "$url" ]; then
  186. $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys E33FF7BF5C91D50A6F91FFFD4CC38D40F9A96B49"
  187. else
  188. $sh_c "$curl ${url}gpg | apt-key add -"
  189. fi
  190. $sh_c "echo deb ${url}ubuntu docker main > /etc/apt/sources.list.d/docker.list"
  191. $sh_c 'sleep 3; apt-get update; apt-get install -y -q lxc-docker'
  192. )
  193. if command_exists docker && [ -e /var/run/docker.sock ]; then
  194. (
  195. set -x
  196. $sh_c 'docker version'
  197. ) || true
  198. fi
  199. echo_docker_as_nonroot
  200. exit 0
  201. ;;
  202. gentoo)
  203. if [ "$url" = "https://test.docker.com/" ]; then
  204. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  205. cat >&2 <<-'EOF'
  206. You appear to be trying to install the latest nightly build in Gentoo.'
  207. The portage tree should contain the latest stable release of Docker, but'
  208. if you want something more recent, you can always use the live ebuild'
  209. provided in the "docker" overlay available via layman. For more'
  210. instructions, please see the following URL:'
  211. https://github.com/tianon/docker-overlay#using-this-overlay'
  212. After adding the "docker" overlay, you should be able to:'
  213. emerge -av =app-emulation/docker-9999'
  214. EOF
  215. exit 1
  216. fi
  217. (
  218. set -x
  219. $sh_c 'sleep 3; emerge app-emulation/docker'
  220. )
  221. exit 0
  222. ;;
  223. esac
  224. # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
  225. cat >&2 <<-'EOF'
  226. Either your platform is not easily detectable, is not supported by this
  227. installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
  228. a package for Docker. Please visit the following URL for more detailed
  229. installation instructions:
  230. https://docs.docker.com/en/latest/installation/
  231. EOF
  232. exit 1
  233. }
  234. # wrapped up in a function so that we have some protection against only getting
  235. # half the file during "curl | sh"
  236. do_install