Centos7.9离线安装Docker24(无坑版)

以下只是以安装Docker 24.0.2为例子,可以照葫芦画瓢安装25或者更高的dcoker版本

总所周知,Docker依赖于Containerd,但不要慌,离线安装包已经自带Containerd了,不需要额外单独去安装Conatinerd

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 conatinerd

在这里插入图片描述

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
  • 15
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值