侧边栏壁纸
博主头像
墨海星辰博主等级

行动起来,活在当下

  • 累计撰写 25 篇文章
  • 累计创建 5 个标签
  • 累计收到 5 条评论

目 录CONTENT

文章目录

Centos系统安装Docker教程,附离线版安装

陪梨去旅行
2024-05-09 / 0 评论 / 0 点赞 / 30 阅读 / 7105 字
温馨提示:
本文最后更新于 2024-08-31,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

在线安装

1. 更新yum源

yum update 

2. 更新yum-utils源

yum install -y yum-utils

3. 安装docker

yum install -y docker

4. 安装docker-compose

使用到docker-compose.yml部署项目时需要安装此功能

4.1 添加docker的yum镜像源

yum-config-manager  --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
#备用
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4.2 安装docker插件

yum -y install docker-compose-plugin

5. 查看docker版本

[root@localhost ~]# docker -v
Docker version 24.0.5, build ced0996
[root@localhost ~]# docker compose version
Docker Compose version v2.20.3

在线安装步骤已经结束,下面是离线安装的步骤。

离线安装

本教程采用二进制安装

1.下载docker离线包

如果您还未下载离线包,链接下载👉 http://blog.fusuccess.top/software/docker-24.0.5.tgz.tar
若想下载其他版本请至官网下载 https://download.docker.com/linux/static/stable/x86_64/

2.解压离线包

tar xvf docker-24.0.5.tgz.tar

3.将解压的docker拷贝或移动到/usr/bin/目录下

cp docker/* /usr/bin/

4.编写docker.service 文件加入Linux服务当中并开启守护进程

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 -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536
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

5.添加文件可执行权限

chmod +x /etc/systemd/system/docker.service

6.配置成功后,重新加载 daemon 服务

systemctl daemon-reload

7.启动 docker 服务

systemctl start docker

常见问题

镜像拉取失败

设置镜像源地址

mkdir -p /etc/docker;
vi /etc/docker/daemon.json

文件内容

{
        "registry-mirrors":
         [
         "https://hub.uuuadc.top",
         "https://docker.anyhub.us.kg",
         "https://dockerhub.jobcher.com",
         "https://dockerhub.icu",
         "https://docker.ckyl.me",
         "https://docker.awsl9527.cn",
         "https://ustc-edu-cn.mirror.aliyuncs.com/",
         "https://ccr.ccs.tencentyun.com/",
         "https://docker.m.daocloud.io/",
         "https://dockerhub.icu",
         "https://docker.registry.cyou",
         "https://docker-cf.registry.cyou",
         "https://dockercf.jsdelivr.fyi",
         "https://docker.jsdelivr.fyi",
         "https://dockertest.jsdelivr.fyi",
         "https://mirror.aliyuncs.com",
         "https://dockerproxy.com",
         "https://mirror.baidubce.com",
         "https://docker.m.daocloud.io",
         "https://docker.nju.edu.cn",
         "https://docker.mirrors.sjtug.sjtu.edu.cn",
         "https://docker.mirrors.ustc.edu.cn",
         "https://mirror.iscas.ac.cn",
         "https://docker.rainbond.cc"
         ]
}

重启docker

sudo systemctl daemon-reload		#重启daemon进程
sudo systemctl restart docker		#重启docker
0

评论区