1.使用场景

在互联网的服务器上可以直接使用yum命令安装docker,但是如果在无网的服务器上,就只能使用离线安装包了

2. 安装

  1. docker离线包下载地址
  2. 准备好docker-service文件

    注意:这里的配置文件里面的ExecStart将docker的存储路径设置成为了/work/docker

  1. [Unit]
  2. Description=Docker Application Container Engine
  3. Documentation=https://docs.docker.com
  4. After=network-online.target firewalld.service
  5. Wants=network-online.target
  6. [Service]
  7. Type=notify
  8. # the default is not to use systemd for cgroups because the delegate issues still
  9. # exists and systemd currently does not support the cgroup feature set required
  10. # for containers run by docker
  11. ExecStart=/usr/bin/dockerd --graph /work/docker
  12. ExecReload=/bin/kill -s HUP $MAINPID
  13. # Having non-zero Limit*s causes performance problems due to accounting overhead
  14. # in the kernel. We recommend using cgroups to do container-local accounting.
  15. LimitNOFILE=infinity
  16. LimitNPROC=infinity
  17. LimitCORE=infinity
  18. # Uncomment TasksMax if your systemd version supports it.
  19. # Only systemd 226 and above support this version.
  20. #TasksMax=infinity
  21. TimeoutStartSec=0
  22. # set delegate yes so that systemd does not reset the cgroups of docker containers
  23. Delegate=yes
  24. # kill only the docker process, not all processes in the cgroup
  25. KillMode=process
  26. # restart the docker process if it exits prematurely
  27. Restart=on-failure
  28. StartLimitBurst=3
  29. StartLimitInterval=60s
  30. [Install]
  31. WantedBy=multi-user.target
  1. 准备好daemon.json文件

    1. {
    2. "log-driver":"json-file",
    3. "log-opts": {"max-size":"500m", "max-file":"3"}
    4. }
  2. 使用tar命令解压,将docker/*所有文件复制或剪切到/usr/bin目录下

  3. 将我们准备好的docker.service复制到/etc/systemd/system目录下(docker.service记得赋执行权限 chmod +x docker.service)
  4. 将我们准备好的daemon.json文件复制或剪切到/etc/docker目录下去,没有此目录就自行创建
  5. 启动docker
    • systemctl daemon-reload: 启动守护进程
    • systemctl start docker: 启动docker
    • systemctl enable docker.service: 开启开机自启动
    • systemctl status docker :验证