Docker
1 前言
一个问题,一篇文章,一出故事。
笔者今天遇到新版本系统需要安装旧版本Docker的问题,发现使用rpm包无法安装,于是想到二进制的解决方案。
2 最佳实践
2.1 环境配置
OS = Oracle Linux 8.x x86_64
IP Addresses = any
Host Name = any
2.2 部署软件包
2.2.1 下载软件包
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.6.tgz
2.2.2 解压软件包
tar -xf docker-20.10.6.tgz
2.2.3 部署软件包
sudo cp docker/* /usr/bin/
2.2.4 创建docker组
groupadd docker
然后,你可以使用如下命令确认组的创建,
getent group docker
2.2.5 测试软件包运行
sudo dockerd &
如果需要结束测试,请执行如下命令,
kill $(pgrep -uroot docker)
2.3 配置服务脚本
2.3.1 创建containerd服务脚本
vim /usr/lib/systemd/system/containerd.service
加入如下配置,
# Copyright The containerd Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. [Unit] Description=containerd container runtime Documentation=https://containerd.io After=network.target local-fs.target [Service] ExecStartPre=-/sbin/modprobe overlay ExecStart=/usr/bin/containerd Type=notify Delegate=yes KillMode=process Restart=always RestartSec=5 # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNPROC=infinity LimitCORE=infinity LimitNOFILE=1048576 # Comment TasksMax if your systemd version does not supports it. # Only systemd 226 and above support this version. TasksMax=infinity OOMScoreAdjust=-999 [Install] WantedBy=multi-user.target
2.3.2 创建docker.socket服务脚本
vim /usr/lib/systemd/system/docker.socket
加入如下配置,
[Unit] Description=Docker Socket for the API [Socket] ListenStream=/var/run/docker.sock SocketMode=0660 SocketUser=root SocketGroup=docker [Install] WantedBy=sockets.target
2.3.3 创建docker服务脚本
vim /usr/lib/systemd/system/docker.service
加入如下配置,
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=docker.socket containerd.service [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 fd:// --containerd=/run/containerd/containerd.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 support 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 OOMScoreAdjust=-500 [Install] WantedBy=multi-user.target
2.3.4 重载服务配置使脚本生效
systemctl daemon-reload
2.3.5 启动服务并设置自动启动
systemctl start containerd systemctl start docker.socket systemctl start docker systemctl enable containerd systemctl enable docker.socket systemctl enable docker systemctl status containerd systemctl status docker.socket systemctl status docker
2.3 配置存储
2.3.1 确定当前存储位置
docker info | egrep -i "Docker Root Dir|Storage Driver"
可见如下显示,
Storage Driver: overlay2 Docker Root Dir: /var/lib/docker
2.3.2 停止Dcoker服务
systemctl stop docker
2.3.3 迁移存储数据
mkdir -p /data/docker/ mv /var/lib/docker /data/docker/runningdata
2.3.4 定义新的存储位置
vim /etc/docker/daemon.json
更改如下参数:
{
"storage-driver": "overlay2",
"data-root": "/data/docker/runningdata"
}
2.3.5 启动Dcoker服务
systemctl start docker
然后,请再次使用如下命令查看服务运行后的存储位置,
docker info | egrep -i "Docker Root Dir|Storage Driver"
可见如下显示,
Storage Driver: overlay2 Docker Root Dir: /data/docker/runningdata
参阅文档
=================
软件包下载
————
https://download.docker.com/linux/static/stable/x86_64/
https://download.docker.com/linux/static/stable/
安装教程
————
https://docs.docker.com/engine/install/binaries/
没有评论