VMware centos7安装docker

centos7安装docker

先决条件

要开始在 CentOS 上使用 Docker 引擎
要安裝 Docker 引擎,你需要一個維持的 CentOS 7 或 8 版本。
不支持或测试存档版本。

我是虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上
1,root账户登录,查看内核版本如下

su root

在这里插入图片描述

uname -a

在这里插入图片描述
查看我们的系统版本信息

cat /etc/os-release
[root@localhost yh]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[root@localhost yh]# 

2.安装
(1)卸载旧版本
旧版本的 Docker 被称为 或 .如果已安装这些项,请将其以及关联的依 赖项一起卸载。

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
[root@localhost yh]# yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
已加载插件:fastestmirror, langpacks
参数 docker 没有匹配
参数 docker-client 没有匹配
参数 docker-client-latest 没有匹配
参数 docker-common 没有匹配
参数 docker-latest 没有匹配
参数 docker-latest-logrotate 没有匹配
参数 docker-logrotate 没有匹配
参数 docker-engine 没有匹配
不删除任何软件包
[root@localhost yh]# 

(2)需要的安装包

yum install -y yum-utils

我这里已经安装

[root@localhost yh]# yum install -y yum-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.bfsu.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理
[root@localhost yh]# 

(3)设置镜像的仓库(这里选用阿里仓库比较快)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost yh]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

更新yum软件包的索引

yum makecache fast
[root@localhost yh]# yum makecache fast
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.bfsu.edu.cn
base                                                            | 3.6 kB  00:00:00     
docker-ce-stable                                                | 3.5 kB  00:00:00     
extras                                                          | 2.9 kB  00:00:00     
updates                                                         | 2.9 kB  00:00:00     
元数据缓存已建立
[root@localhost yh]# 

(4)安装最新版本的 Docker 引擎和 containerd

yum install docker-ce docker-ce-cli containerd.io

(期间要选择确认,输入 y 即可)

[root@localhost yh]# yum install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.bfsu.edu.cn
软件包 3:docker-ce-20.10.14-3.el7.x86_64 已安装并且是最新版本
软件包 1:docker-ce-cli-20.10.14-3.el7.x86_64 已安装并且是最新版本
软件包 containerd.io-1.5.11-3.1.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost yh]# 

3.启动dokcer

systemctl start docker

设置开机启动docker服务:

systemctl enable docker
[root@localhost yh]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost yh]# 

查看是否安装成功

docker version
#docker的版本信息
[root@localhost yh]# docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:49:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:48:24 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost yh]# 

4.验证docker是否正确安装

#此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条消息并退出。
这将安装并运行 Docker 引擎。用于运行 Docker 命令。
docker run hello-world

运行如下代表他当前没有找到镜像image’hello-world’,然后会从library拉取’hello-world’镜像信息,下载镜像。
在这里插入图片描述

[root@localhost yh]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[root@localhost yh]# 

查看已下载的镜像信息

docker images
[root@localhost yh]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   7 months ago   13.3kB
[root@localhost yh]# 

docker安装成功

附上docker官网安装文档

### 在 VMware 上的 CentOS 7 系统中安装和配置 Docker #### 准备工作 在开始安装前,需确认已成功完成以下操作: - 已经通过 VMware 创建了一个虚拟机,并完成了 CentOS 7 的操作系统安装[^4]。 - 确保系统的网络连接正常,以便后续能够访问互联网下载必要的软件包。 #### 卸载旧版 Docker 如果系统上已经存在旧版本的 Docker,则需要先将其卸载。执行以下命令来移除可能存在的旧版本组件: ```bash sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine ``` 此步骤有助于避免新旧版本冲突[^5]。 #### 安装必要工具 `yum-utils` 为了管理 Docker 的存储库,需要安装 `yum-utils` 软件包,它提供了用于添加自定义存储库的实用程序 `yum-config-manager`: ```bash sudo yum install -y yum-utils ``` #### 配置阿里云镜像源 为提高下载速度并减少因地域原因造成的延迟,建议使用国内的阿里云镜像作为 Docker 的官方仓库地址。运行如下命令以添加新的仓库配置文件: ```bash sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ``` 上述命令会将 Aliyun 提供的 Docker CE 存储库加入到 YUM 中[^1]。 #### 更新本地缓存 更新本地的元数据缓存以反映最新可用的软件包列表: ```bash sudo yum makecache fast ``` #### 安装指定或默认版本的 Docker 可以选择安装特定版本或者直接获取最新的稳定发行版: ##### 方法 A: 安装最新版本 若无特殊需求,默认安装最新发布的 Docker 版本即可满足大多数场景下的应用开发与部署任务: ```bash sudo yum -y install docker-ce docker-ce-cli containerd.io ``` 这条语句包含了核心引擎及其 CLI 接口还有底层容器运行时的支持[^2]。 ##### 方法 B: 指定具体版本号进行安装 当项目依赖某个固定的小版本时,可以通过查询可选版本后再手动挑选适合自己的选项。例如要安装 v18.03.1.ce 可按下面方式实现: ```bash yum list docker-ce --showduplicates | sort -r sudo yum -y install docker-ce-18.03.1.ce ``` 这里展示了如何查看所有候选版本以及实际选取的过程[^3]。 #### 启动服务并设置开机自启 完成以上步骤之后,还需要激活 Docker 并设定其随系统引导自动加载: ```bash sudo systemctl start docker sudo systemctl enable docker ``` 至此,在 VMware 所托管的 CentOS 7 主机之上就顺利集成了功能完备的企业级容器化平台——Docker! ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jr 野良

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值