文章目录
以下只是以安装Docker 24.0.2为例子,可以照葫芦画瓢安装25或者更高的dcoker版本
总所周知,Docker依赖于Containerd,但不要慌,离线安装包已经自带Containerd了,不需要额外单独去安装Containerd
1 下载并上传docker离线安装包
选择以下任意一个网站进行安装包下载:
docker官方网站安装包地址:https://download.docker.com/linux/static/stable/x86_64/
阿里云docker安装包下载地址:https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/
安装包下载后,将安装包传至服务器上。
2 docker安装
2.1 安装包解压
tar -zxvf docker-24.0.2.tgz
2.2 移动docker相关二进制文件
拷贝二进制文件到/usr/local/bin/目录下
cp docker/* /usr/bin/
2.3创建docker启停文件
cat << EOF > /usr/lib/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
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
EOF
2.3 创建Containerd启停文件
cat << EOF > /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/local/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
# 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
EOF
注意:containerd.service你也可以自行通过以下网站进行下载:
点我下载containerd.service文件
然后再传到 /usr/lib/systemd/system/目录下,但请注意!!,此时containerd.service文件启动containerd默认是从/usr/local/bin/目录读取containerd,而不是/usr/bin/,故而需要自行改一下路径。
可以通过该命令进行替换 “sed -i ‘s//usr/local/bin/containerd//usr/bin/containerd/g’ containerd.service”
3 启动并验证
3.1 启动Containerd
启动并设置开机自启动
systemctl enable --now containerd
检查是否启动成功
systemctl status containerd
3.2 启动Docker
启动并设置开机自启动
systemctl enable --now docker
检查是否启动成功
systemctl status docker
4 镜像加速
创建docker配置目录
mkdir /etc/docker
docker配置加速
cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://ccr.ccs.tencentyun.com"
]
}
EOF
让加速配置生效
systemctl daemon-reload
systemctl restart docker
验证,下一个centos7镜像
docker pull centos:7
速度很快~~~~
5 docker-compose安装
docker-compose下载地址:https://github.com/docker/compose/releases/
我这里选择安装2.5版本
将文件下载后上传至服务器,然后进行以下操作
#授予执行权限
chmod +x docker-compose-linux-x86_64
# 移动并命名 docker-compose文件
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
# 验证
docker-compose -v
其他
设置docker数据目录
默认docker数据目录是/var/lib/docker,如果想修改,可以通过以下方式
vim /etc/docker/daemon.json
{
...其他配置,
"data-root": "/data/docker"
}
让配置生效
systemctl daemon-reload
systemctl restart docker
设置docker 容器日志大小
设置日期日志文件为json-file类型
单个容器最大日志大小为500M,最多有三个日志文件。
vim /etc/docker/daemon.json
{
...其他配置,
"log-driver": "json-file",
"log-opts": {"max-size":"500m", "max-file":"3"}
}
shell脚本一键部署docker容器(含docker-compose)
脚本里面的操作也是基于本文章的内容:
资源下载地址:https://download.csdn.net/download/jianghuchuang/90350377
安装命令:sh docker-offline-install.sh