install_docker.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ## Install Docker
  2. # https://docs.docker.com/engine/install/debian/
  3. sudo -i
  4. # Install dependencies
  5. apt-get update && apt-get install --yes \
  6. ca-certificates \
  7. curl \
  8. gnupg \
  9. lsb-release
  10. # Add trust and docker apt repo
  11. mkdir -m 0755 -p /etc/apt/keyrings
  12. curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  13. echo \
  14. "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  15. $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
  16. # Install docker
  17. apt-get update && apt-get install --yes \
  18. docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  19. # allow admin to use the docker command
  20. usermod --append --groups docker admin
  21. #----------
  22. # 1) Setup journald as log driver so we don't need to care separetly for log rotation
  23. #
  24. # 2) Change Docker Address pools
  25. # Docker default address address pools:
  26. # Vanilla
  27. # 172.17.0.0/12 split in /16 (size) => 16 networks each 65536 hosts
  28. # 192.168.0.0/16 split in /24 (size) => 256 networks each 256 hosts
  29. # More details: # https://straz.to/2021-09-08-docker-address-pools/
  30. # Reasons to change
  31. # - Short: The configuration is not suitable for our home server
  32. # - 192.168.0.0/16 is frequently used in the home environment
  33. # - 172.17.0.0/12 size doesn't offer enough networks and we never have that many hosts
  34. # Resulting configuraiton
  35. # 172.16.0.0/12 split in /22 (size) => 1024 networks each 1024 hosts
  36. # nnnn nnnn . nnnn NNNN . NNNN NNhh . hhhh hhhh
  37. # 12 2^10 22 2^10 32
  38. # But, we start with 172.18.0.0 and
  39. # (1) leave 172.16.0.0/16 untouched
  40. # (2.1) assign 172.17.0.0/22 to the default bridge
  41. # (2.2) use the remaing networks for special purposes 172.17.4.0, 172.17.8.0, 172.17.12.0, ...
  42. # => (1)+(2) takes each 64 /22-networks, resulting in 896 networks (1024-128)
  43. #
  44. # Tools: https://www.site24x7.com/tools/ipv4-subnetcalculator.html
  45. # Reference: RFC 1918 name: 172.16.0.0 - 172.31.255.255
  46. #
  47. # Check configuration: docker info | grep Base
  48. # Check configuration: docker network inspect bridge | grep Subnet
  49. cat >/etc/docker/daemon.json <<EOL
  50. {
  51. "log-driver": "journald",
  52. "bip": "172.17.0.1/22",
  53. "default-address-pools": [
  54. {
  55. "base": "172.18.0.0/12",
  56. "size": 20
  57. }
  58. ]
  59. }
  60. EOL
  61. systemctl restart docker.service
  62. # Create directory for docker
  63. mkdir -p /opt/docker
  64. docker run hello-world