Skip to content

Docker离线安装

公司的一些场景下,需要离线安装docker,并需要将之整理为文档,交付运维安装与维护。

故本文主要介绍docker离线安装,且假设你对docker已经比较熟悉。

本文安装以centos 7 为操作系统,且为正常安装包,非精简安装(缺失组件太多)。

RPM 方式

操作步骤

  1. 下载离线包
  2. 确认缺失组件
  3. 安装docker
  4. 编写系统服务
  5. 验证是否成功

一、 下载离线包

下载rpm包:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

清单如下:

这里版本为 18.09.1 ,后续请自行找最新版本号,进行下载。

docker-ce-18.09.1-3.el7.x86_64.rpm

docker-ce-cli-18.09.1-3.el7.x86_64.rpm

docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm

二、 确认缺失组件

根据系统版本不同会有一些RPM只是更新更,如果存在缺失包的情况。

请到如下地址进行下载:

http://mirrors.163.com/centos/7/os/x86_64/Packages/

三、安装docker

rpm -ivh docker_download/*.rpm

这个过程中可能涉及缺失,请查阅步骤二中方式进行补充。
四、编写系统服务
安装完成之后,其服务配置文件路径为 /usr/lib/systemd/system/docker.service。

如果需要开放远程控制则需要修改:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

添加红色部分。

重启docker服务

systemctl restart docker

五、验证是否成功

docker version

Client:
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:35:01 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false

压缩包方式

压缩包安装方式需要手工操作多一点。

操作步骤

  1. 下载安装包
  2. 解压安装
  3. 配置系统服务
  4. 验证版本

一、下载安装包

首先到官方进行相关离线安装包下载。

https://download.docker.com/linux/static/stable/x86_64/

这里我们以18.9.1 为例。

下载  docker-18.09.1.tgz

二、 解压安装

tar -zxvf docker-18.09.1.tgz

sudo cp docker/* /user/bin/

三、 配置系统服务

这种安装方式则没有默认的系统服务,则需要自行建立。

vim /usr/lib/systemd/system/docker.service

粘贴以下内容:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

红色部分 为远程控制部分,如无需要请删除。

重新加载系统服务

systemctl daemon-reload

启动docker 服务

systemctl restart docker

 

五、验证是否成功

docker version

Client:
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:35:01 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false
发表评论

电子邮件地址不会被公开。 必填项已用*标注