Docker安装指引

安装前准备

  1. 准备一台linux主机, 本安装指引以腾讯云上的虚拟机为例;
  2. 建议操作系统为centos7.2.建议内核版本为3.10.517以上;
  3. 网络可通外网,需远程下载安装软件; 以下安装配置操作均在root用户下执行。

安装步骤

  1. 下载二进制包到本地

    1. mkdir /data/
    2. cd /data
    3. wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
  2. 解压二进制包

    1. tar xzvf docker-18.06.3-ce.tgz
    2. mv docker/* /usr/bin
  3. 创建/etc/docker目录,创建配置文件/etc/docker/daemon.json,将下列内容拷贝到文件中

    1. {
    2. "bip": "169.254.32.1/28",
    3. "bridge": "",
    4. "debug": false,
    5. "default-runtime": "runc",
    6. "exec-opts": [],
    7. "exec-root": "",
    8. "graph": "/var/lib/docker",
    9. "group": "",
    10. "insecure-registries": [],
    11. "ip-forward": true,
    12. "ip-masq": true,
    13. "iptables": true,
    14. "ipv6": false,
    15. "labels": [],
    16. "live-restore": true,
    17. "log-driver": "json-file",
    18. "log-level": "warn",
    19. "log-opts": {
    20. "max-file": "10",
    21. "max-size": "100m"
    22. },
    23. "registry-mirrors": [
    24. "https://mirror.ccs.tencentyun.com"
    25. ],
    26. "runtimes": {},
    27. "selinux-enabled": false,
    28. "storage-driver": "overlay2",
    29. "storage-opts": [
    30. "overlay2.override_kernel_check=true"
    31. ]
    32. }
  4. 创建docker服务文件/lib/systemd/system/dockerd.service,将下列内容拷贝到文件中

    1. [Unit]
    2. Description=dockerd
    3. [Service]
    4. Environment=QCLOUD_NORM_URL=
    5. Type=notify
    6. ExecStart=/usr/bin/dockerd --config-file=/etc/docker/daemon.json
    7. ExecStartPre=/bin/rm -f /var/run/docker.pid
    8. ExecStartPost=-/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
    9. ExecReload=/bin/kill -s HUP $MAINPID
    10. LimitNOFILE=1048576
    11. LimitNPROC=1048576
    12. LimitCORE=infinity
    13. TimeoutStartSec=0
    14. Delegate=yes
    15. KillMode=process
    16. Restart=always
    17. RestartSec=10
    18. [Install]
    19. WantedBy=multi-user.target
  5. 创建服务并启动

    1. systemctl enable dockerd
    2. systemctl start dockerd
  6. 运行命令确认docker安装成功

    1. docker --version

    docker_version

设置内核参数

  1. 编辑内核参数文件/etc/sysctl.conf,确认这几个选项如下:

    1. net.ipv4.ip_forward=1
    2. net.bridge.bridge-nf-call-ip6tables = 1
    3. net.bridge.bridge-nf-call-iptables = 1
  2. 执行命令

    1. sysctl -p