install.sh 7.3 KB

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