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

在线安装

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

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://ustc-edu-cn.mirror.aliyuncs.com/",
        "https://ccr.ccs.tencentyun.com/",
        "https://docker.m.daocloud.io/"
    ]
}

重启docker

sudo systemctl daemon-reload		#重启daemon进程
sudo systemctl restart docker		#重启docker
  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值