在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/++

相关推荐
辉的技术笔记16 小时前
Dify 自部署为什么跑不动?6 层瓶颈诊断法教你定位
docker
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
程序员老赵2 天前
Docker 部署 Redmine:老牌开源项目管理部署实测记录
docker·开源·团队管理
用户120487221612 天前
Linux驱动编译与加载
linux·嵌入式
程序员老赵2 天前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698032 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux