docker-install.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
  7. color
  8. verb_ip6
  9. catch_errors
  10. setting_up_container
  11. network_check
  12. update_os
  13. msg_info "Installing Dependencies"
  14. $STD apt-get install -y curl
  15. $STD apt-get install -y sudo
  16. $STD apt-get install -y mc
  17. msg_ok "Installed Dependencies"
  18. get_latest_release() {
  19. curl -sL https://api.github.com/repos/$1/releases/latest | grep '"tag_name":' | cut -d'"' -f4
  20. }
  21. DOCKER_LATEST_VERSION=$(get_latest_release "moby/moby")
  22. PORTAINER_LATEST_VERSION=$(get_latest_release "portainer/portainer")
  23. DOCKER_COMPOSE_LATEST_VERSION=$(get_latest_release "docker/compose")
  24. msg_info "Installing Docker $DOCKER_LATEST_VERSION"
  25. DOCKER_CONFIG_PATH='/etc/docker/daemon.json'
  26. mkdir -p $(dirname $DOCKER_CONFIG_PATH)
  27. if [ "$ST" == "yes" ]; then
  28. VER=$(curl -s https://api.github.com/repos/containers/fuse-overlayfs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
  29. cd /usr/local/bin
  30. curl -sSL -o fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/$VER/fuse-overlayfs-x86_64
  31. chmod 755 /usr/local/bin/fuse-overlayfs
  32. cd ~
  33. echo -e '{\n "storage-driver": "fuse-overlayfs",\n "log-driver": "journald"\n}' > /etc/docker/daemon.json
  34. else
  35. echo -e '{\n "log-driver": "journald"\n}' > /etc/docker/daemon.json
  36. fi
  37. $STD sh <(curl -sSL https://get.docker.com)
  38. msg_ok "Installed Docker $DOCKER_LATEST_VERSION"
  39. read -r -p "Would you like to add Portainer? <y/N> " prompt
  40. if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
  41. msg_info "Installing Portainer $PORTAINER_LATEST_VERSION"
  42. docker volume create portainer_data >/dev/null
  43. $STD docker run -d \
  44. -p 8000:8000 \
  45. -p 9000:9000 \
  46. --name=portainer \
  47. --restart=always \
  48. -v /var/run/docker.sock:/var/run/docker.sock \
  49. -v portainer_data:/data \
  50. portainer/portainer-ce:latest
  51. msg_ok "Installed Portainer $PORTAINER_LATEST_VERSION"
  52. fi
  53. read -r -p "Would you like to add Docker Compose? <y/N> " prompt
  54. if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
  55. msg_info "Installing Docker Compose $DOCKER_COMPOSE_LATEST_VERSION"
  56. DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
  57. mkdir -p $DOCKER_CONFIG/cli-plugins
  58. curl -sSL https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_LATEST_VERSION/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
  59. chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
  60. msg_ok "Installed Docker Compose $DOCKER_COMPOSE_LATEST_VERSION"
  61. fi
  62. motd_ssh
  63. root
  64. msg_info "Cleaning up"
  65. $STD apt-get autoremove
  66. $STD apt-get autoclean
  67. msg_ok "Cleaned"