Docker官方的安装指南

一、安装yum工具

  1. [root@k8s-5-146 ~]# yum install -y yum-utils \
  2. device-mapper-persistent-data \
  3. lvm2

二、配置yum源

  1. # 如果下面命令执行超时,可以使用阿里云的源代替:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. [root@k8s-5-146 ~]# yum-config-manager \
  3. --add-repo \
  4. https://download.docker.com/linux/centos/docker-ce.repo
  5. # 检查yum源中有哪些版本的 docker-ce
  6. [root@k8s-5-146 ~]# yum list docker-ce --showduplicates | sort -r

三、安装docker

  1. # 我安装的是 20.10.6 版本
  2. [root@k8s-5-146 ~]# yum install docker-ce-20.10.6

四、配置 Docker 镜像加速器: 和bip

  1. [root@k8s-5-146 ~]# mkdir -p /etc/docker # 如果没有这个目录先创建,然后添加 daemon.json 文件
  2. [root@k8s-5-146 ~]# vi /etc/docker/daemon.json
  3. {
  4. "exec-opts": ["native.cgroupdriver=systemd"],
  5. "registry-mirrors" : [
  6. "https://ot2k4d59.mirror.aliyuncs.com/"
  7. ],
  8. "bip": "172.5.146.1/24", #如果是在K8s集群中的服务器上安装docker,为了避免多台服务器docker的bip重复,最好为每台机器设置不同的bip
  9. "mtu": 1400
  10. }

cgroup 驱动 由于默认情况下 kubelet 使用的 cgroupdriver 是 systemd,所以需要保持 docker 和kubelet 的 cgroupdriver 一致,我们这里修改 docker 的 cgroupdriver=systemd。如果不修改 docker 则需要修改 kubelet 的启动配置,需要保证两者一致。

五、配置docker开机启动

  1. [root@k8s-5-146 ~]# systemctl start docker
  2. [root@k8s-5-146 ~]# systemctl enable docker
  3. [root@k8s-5-146 ~]# docker info
  4. Client:
  5. Context: default
  6. Debug Mode: false
  7. Plugins:
  8. app: Docker App (Docker Inc., v0.9.1-beta3)
  9. buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  10. scan: Docker Scan (Docker Inc.)
  11. Server:
  12. Containers: 0
  13. Running: 0
  14. Paused: 0
  15. Stopped: 0
  16. Images: 0
  17. Server Version: 20.10.6
  18. Storage Driver: overlay2
  19. Backing Filesystem: xfs
  20. Supports d_type: true
  21. Native Overlay Diff: true
  22. userxattr: false
  23. Logging Driver: json-file
  24. Cgroup Driver: systemd
  25. Cgroup Version: 1
  26. Plugins:
  27. Volume: local
  28. Network: bridge host ipvlan macvlan null overlay
  29. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  30. Swarm: inactive
  31. Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
  32. Default Runtime: runc
  33. Init Binary: docker-init
  34. containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
  35. runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
  36. init version: de40ad0
  37. Security Options:
  38. seccomp
  39. Profile: default
  40. Kernel Version: 3.10.0-862.el7.x86_64
  41. Operating System: CentOS Linux 7 (Core)
  42. OSType: linux
  43. Architecture: x86_64
  44. CPUs: 2
  45. Total Memory: 1.779GiB
  46. Name: k8s-5-146.k8s.host
  47. ID: P2QS:PHLB:L5EU:BUFL:QMQ7:X2L4:ADIJ:UFCT:32Z3:SGFT:LJZP:TT4D
  48. Docker Root Dir: /var/lib/docker
  49. Debug Mode: false
  50. Registry: https://index.docker.io/v1/
  51. Labels:
  52. Experimental: false
  53. Insecure Registries:
  54. 127.0.0.0/8
  55. Registry Mirrors:
  56. https://ot2k4d59.mirror.aliyuncs.com/
  57. Live Restore Enabled: false

以上, docker 就安装完成啦