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安装成功
版权声明:本文为weixin_46065653原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。