3. 离线安装docker

3.0 检查卸载已有docker

查看是否安装 docker yum list installed | grep docker

卸载docker yum remove docker docker-common container-selinux docker-selinux docker-engineyum remove -y docker-*

3.1 下载安装包

要下载docker-18.06.x-ce版本,否则有些不支持 k8s。。请看版本支持 https://rancher.com/docs/rancher/v1.6/en/hosts/#supported-docker-versions

docker-18.06.x-ce下载地址 https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz

3.2 安装docker

解压 tar zxvf docker-18.06.3-ce.tgz

将解压出来的docker文件内容移动到 /usr/bin/ 目录下 cp docker/* /usr/bin/

将docker注册为service服务 vim /etc/systemd/system/docker.service
编辑内容为:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[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
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

加权限 chmod +x /etc/systemd/system/docker.service

3.3 启动docker,查看结果

启动docker
systemctl daemon-reload && systemctl start docker && systemctl enable docker.service

systemctl daemon-reload #重新加载daemon
systemctl start docker #启动Docker
systemctl enable docker.service #设置开机自启

查看状态 systemctl status docker
docker版本 docker version

3.4 修改配置文件

修改docker数据默认存储地址:
首先在/home下创建 /data/docker,用于存储docker的镜像和数据 mkdir -p /home/data/docker

docker镜像和数据默认存储在 /var/lib/docker 中,
修改 /etc/docker/daemon.json ,vim /etc/docker/daemon.json,没有这个文件,会自动创建
修改内容如下(使用国内阿里云docker镜像库【详解请再往下看】,路径为刚刚创建的目录):

{
"registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/"],
"graph":"/home/data/docker"
}

关于registry-mirrors:
其中registry-mirrors是我使用的阿里云镜像加速服务,这个地址是不相同的。
浏览器进入 阿里云(www.aliyun.com)
在上边的搜索框中搜索 镜像加速服务 ,点击进入“官方镜像加速-容器镜像服务”
左侧点击 “快速入门”- “官方镜像加速”
点击“容器镜像服务控制台”

在这里插入图片描述
点击左侧 “镜像中心”- “镜像加速器”
可以看到url地址,将上述registry-mirrors地址替换掉即可

保险起见,重加载配置文件 重启docker
systemctl daemon-reload && systemctl restart docker

查看信息
docker info
Docker Root Dir 默认路径

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐