在CentOS中安装docker

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

一、前提

1、查看内核版本

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

2、更新软件包

耗时较长

yum update -y

3、安装yum-utils软件包

yum -y install yum-utils

4、设置存储库

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

不标注版本为最新版本

yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

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

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、 查看版本

docker version

2、 启动服务

systemctl start docker

service docker start

3、查看服务

输入命令

systemctl status docker

service docker status

打印返回

● 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/

你可能感兴趣的:(#,Docker,工具使用,centos,docker,linux)