在CentOS中安装docker

|---------------------------------------------------------------------------------------------------|
| 环境:CentOS 7 目的:安装docker、启动服务 依据: ++🔗官方文档++ |

一、前提

1、查看内核版本

bash 复制代码
uname -r

|--------------------------------------------|
| Tip:docker需要内核版本3.10以上。所以CentOS 7是最低要求 |

2、更新软件包

耗时较长

bash 复制代码
yum update -y

3、安装yum-utils软件包

bash 复制代码
yum -y install yum-utils

4、设置存储库

bash 复制代码
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

打印返回

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo |

二、安装docker

不标注版本为最新版本

bash 复制代码
yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

标注版本举例(3:24.0.0-1.el8 版本)

bash 复制代码
yum install docker-ce-3:24.0.0-1.el8 docker-ce-cli-3:24.0.0-1.el8 containerd.io docker-buildx-plugin docker-compose-plugin

三、启动docker

1、 查看版本

bash 复制代码
docker version

2、 启动服务

bash 复制代码
systemctl start docker

bash 复制代码
service docker start

3、查看服务

输入命令

bash 复制代码
systemctl status docker

bash 复制代码
service docker status

打印返回

bash 复制代码
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-12-06 17:10:11 PST; 13min ago
     Docs: https://docs.docker.com
 Main PID: 9683 (dockerd)
    Tasks: 10
   Memory: 26.5M
   CGroup: /system.slice/docker.service
           └─9683 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Dec 06 17:10:10 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:10.604776861-08:00" level=info msg="Firewalld: docker zone already exists, returning"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.011649899-08:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.067298553-08:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.447546399-08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to...rred IP address"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.666608075-08:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.853674881-08:00" level=info msg="Loading containers: done."
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.898342204-08:00" level=info msg="Docker daemon" commit=311b9ff graphdriver=overlay2 version=24.0.7
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.898526692-08:00" level=info msg="Daemon has completed initialization"
Dec 06 17:10:11 localhost.localdomain dockerd[9683]: time="2023-12-06T17:10:11.950866539-08:00" level=info msg="API listen on /run/docker.sock"
Dec 06 17:10:11 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

四、一些问题?

1、启动服务报Failed to start docker.service: Unit not found.

执行systemctl start docker后出现以下错误

|-------------------------------------------------|
| Failed to start docker.service: Unit not found. |

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 原因: docker服务没有正常安装上 解决方法: 执行docker version命令查看有没有打印版本 ① 若没有则重新安装docker,执行 yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ②若仍无法解决,参考 ++🔗https://blog.csdn.net/weixin_53592309/article/details/124695944++ |


参考官方文档: ++🔗https://docs.docker.com/engine/install/centos/++

相关推荐
矛取矛求3 分钟前
Linux系统性能调优技巧
linux
One_Blanks7 分钟前
渗透测试-Linux基础(1)
linux·运维·安全
Perishell8 分钟前
无人机避障——大疆与Airsim中的角速度信息订阅获取
linux·动态规划·无人机
爱吃喵的鲤鱼11 分钟前
linux进程的状态之环境变量
linux·运维·服务器·开发语言·c++
dessler23 分钟前
Linux系统-ubuntu系统安装
linux·运维·云计算
荒Huang1 小时前
Linux挖矿病毒(kswapd0进程使cpu爆满)
linux·运维·服务器
MonkeyKing_sunyuhua1 小时前
ubuntu22.04 docker-compose安装postgresql数据库
数据库·docker·postgresql
追风林2 小时前
mac m1 docker本地部署canal 监听mysql的binglog日志
java·docker·mac
€☞扫地僧☜€3 小时前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
茶馆大橘3 小时前
微服务系列六:分布式事务与seata
分布式·docker·微服务·nacos·seata·springcloud