linux安装docker
安装docker
关闭防火墙和selinux
安装工具包
[root@docker ~]# yum -y install yum-utils
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Determining fastest mirrors
zgf | 3.6 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-45.el7 将被 安装
--> 正在处理依赖关系 python-kitchen,它被软件包 yum-utils-1.1.31-45.el7.noarch 需要
--> 正在检查事务
---> 软件包 python-kitchen.noarch.0.1.1.1-5.el7 将被 安装
--> 正在处理依赖关系 python-chardet,它被软件包 python-kitchen-1.1.1-5.el7.noarch 需要
--> 正在检查事务
---> 软件包 python-chardet.noarch.0.2.2.1-1.el7_1 将被 安装
--> 解决依赖关系完成
依赖关系解决
==============================================================================================================================================================
Package 架构 版本 源 大小
==============================================================================================================================================================
正在安装:
yum-utils noarch 1.1.31-45.el7 zgf 119 k
为依赖而安装:
python-chardet noarch 2.2.1-1.el7_1 zgf 227 k
python-kitchen noarch 1.1.1-5.el7 zgf 267 k
事务概要
==============================================================================================================================================================
安装 1 软件包 (+2 依赖软件包)
总下载量:613 k
安装大小:2.8 M
Downloading packages:
--------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 532 kB/s | 613 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : python-chardet-2.2.1-1.el7_1.noarch 1/3
正在安装 : python-kitchen-1.1.1-5.el7.noarch 2/3
正在安装 : yum-utils-1.1.31-45.el7.noarch 3/3
验证中 : yum-utils-1.1.31-45.el7.noarch 1/3
验证中 : python-chardet-2.2.1-1.el7_1.noarch 2/3
验证中 : python-kitchen-1.1.1-5.el7.noarch 3/3
已安装:
yum-utils.noarch 0:1.1.31-45.el7
作为依赖被安装:
python-chardet.noarch 0:2.2.1-1.el7_1 python-kitchen.noarch 0:1.1.1-5.el7
完毕!
配置docker软件包的地址(此处为阿里云的docker镜像)
[root@docker ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://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
安装docker(此处报错)
[root@docker ~]# yum -y install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Loading mirror speeds from cached hostfile
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db | 82 kB 00:00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.8-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.8-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-20.10.18-3.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.18-3.el7.x86_64 需要
--> 正在处理依赖关系 libcgroup,它被软件包 3:docker-ce-20.10.18-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 docker-scan-plugin(x86-64),它被软件包 1:docker-ce-cli-20.10.18-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.8-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.8-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-20.10.18-3.el7.x86_64 需要
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.18-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.18-3.el7.x86_64 需要
---> 软件包 docker-scan-plugin.x86_64.0.0.17.0-3.el7 将被 安装
---> 软件包 libcgroup.x86_64.0.0.41-15.el7 将被 安装
--> 解决依赖关系完成
错误:软件包:containerd.io-1.6.8-3.1.el7.x86_64 (docker-ce-stable)
需要:container-selinux >= 2:2.74
错误:软件包:docker-ce-rootless-extras-20.10.18-3.el7.x86_64 (docker-ce-stable)
需要:fuse-overlayfs >= 0.7
错误:软件包:3:docker-ce-20.10.18-3.el7.x86_64 (docker-ce-stable)
需要:container-selinux >= 2:2.74
错误:软件包:docker-ce-rootless-extras-20.10.18-3.el7.x86_64 (docker-ce-stable)
需要:slirp4netns >= 0.4
您可以尝试添加 --skip-broken 选项来解决该问题
您可以尝试执行:rpm -Va --nofiles --nodigest
解决安装出错
这个报错是container-selinux版本低或者是没安装的原因
yum 安装container-selinux 一般的yum源又找不到这个包
需要安装epel源 才能yum安装container-selinux
下载安装epel源
安装wget
[root@docker ~]# yum provides wget
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Loading mirror speeds from cached hostfile
wget-1.14-15.el7_4.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
源 :zgf
[root@docker ~]# yum -y install wget-1.14-15.el7_4.1.x86_64
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 wget.x86_64.0.1.14-15.el7_4.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
==============================================================================================================================================================
Package 架构 版本 源 大小
==============================================================================================================================================================
正在安装:
wget x86_64 1.14-15.el7_4.1 zgf 547 k
事务概要
==============================================================================================================================================================
安装 1 软件包
总下载量:547 k
安装大小:2.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : wget-1.14-15.el7_4.1.x86_64 1/1
验证中 : wget-1.14-15.el7_4.1.x86_64 1/1
已安装:
wget.x86_64 0:1.14-15.el7_4.1
完毕!
下载epel源
https://mirrors.aliyun.com/repo/Centos-7.repo和http://mirrors.aliyun.com/repo/Centos-7.repo都可以。(此处我下载了两个地址的epel源做测试,测试结束后删除了其中一个。)
[root@docker ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2022-09-13 21:30:15-- https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 27.221.120.238, 27.221.120.239, 27.221.120.243, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|27.221.120.238|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[====================================================================================================================>] 2,523 --.-K/s 用时 0s
2022-09-13 21:30:15 (192 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
[root@docker ~]# wget -O /etc/yum.repos.d/CentOS-Base02.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2022-09-13 21:30:54-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 27.221.120.241, 27.221.120.244, 27.221.120.238, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|27.221.120.241|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base02.repo”
100%[====================================================================================================================>] 2,523 --.-K/s 用时 0s
2022-09-13 21:30:55 (407 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base02.repo” [2523/2523])
[root@docker ~]# ls /etc/yum.repos.d/
CentOS-Base02.repo CentOS-Base.repo docker-ce.repo zgf.repo
[root@docker ~]# rm -rf /etc/yum.repos.d/CentOS-Base02.repo
[root@docker ~]# ls /etc/yum.repos.d/
CentOS-Base.repo docker-ce.repo zgf.repo
安装epel源,安装container-selinux
yum -y install epel-release
yum makecache
yum -y install container-selinux
解决报错后再次安装docker
[root@docker ~]# yum -y install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.8-3.1.el7 将被 安装
---> 软件包 docker-ce.x86_64.3.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.18-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 docker-scan-plugin(x86-64),它被软件包 1:docker-ce-cli-20.10.18-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.18-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.18-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.18-3.el7.x86_64 需要
---> 软件包 docker-scan-plugin.x86_64.0.0.17.0-3.el7 将被 安装
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==============================================================================================================================================================
Package 架构 版本 源 大小
==============================================================================================================================================================
正在安装:
containerd.io x86_64 1.6.8-3.1.el7 docker-ce-stable 33 M
docker-ce x86_64 3:20.10.18-3.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:20.10.18-3.el7 docker-ce-stable 30 M
为依赖而安装:
docker-ce-rootless-extras x86_64 20.10.18-3.el7 docker-ce-stable 8.5 M
docker-scan-plugin x86_64 0.17.0-3.el7 docker-ce-stable 3.7 M
fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k
fuse3-libs x86_64 3.6.1-4.el7 extras 82 k
slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k
事务概要
==============================================================================================================================================================
安装 3 软件包 (+5 依赖软件包)
总下载量:97 M
安装大小:369 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.18-3.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY 00:00:11 ETA
docker-ce-20.10.18-3.el7.x86_64.rpm 的公钥尚未安装
(1/8): docker-ce-20.10.18-3.el7.x86_64.rpm | 22 MB 00:00:08
(2/8): containerd.io-1.6.8-3.1.el7.x86_64.rpm | 33 MB 00:00:13
(3/8): docker-ce-rootless-extras-20.10.18-3.el7.x86_64.rpm | 8.5 MB 00:00:03
(4/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(5/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00
(6/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(7/8): docker-scan-plugin-0.17.0-3.el7.x86_64.rpm | 3.7 MB 00:00:01
(8/8): docker-ce-cli-20.10.18-3.el7.x86_64.rpm | 30 MB 00:00:09
--------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 5.3 MB/s | 97 MB 00:00:18
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
用户ID : "Docker Release (CE rpm) <docker@docker.com>"
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : docker-scan-plugin-0.17.0-3.el7.x86_64 1/8
正在安装 : 1:docker-ce-cli-20.10.18-3.el7.x86_64 2/8
正在安装 : slirp4netns-0.4.3-4.el7_8.x86_64 3/8
正在安装 : containerd.io-1.6.8-3.1.el7.x86_64 4/8
正在安装 : fuse3-libs-3.6.1-4.el7.x86_64 5/8
正在安装 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 6/8
正在安装 : 3:docker-ce-20.10.18-3.el7.x86_64 7/8
正在安装 : docker-ce-rootless-extras-20.10.18-3.el7.x86_64 8/8
验证中 : fuse3-libs-3.6.1-4.el7.x86_64 1/8
验证中 : containerd.io-1.6.8-3.1.el7.x86_64 2/8
验证中 : docker-ce-rootless-extras-20.10.18-3.el7.x86_64 3/8
验证中 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 4/8
验证中 : 3:docker-ce-20.10.18-3.el7.x86_64 5/8
验证中 : slirp4netns-0.4.3-4.el7_8.x86_64 6/8
验证中 : 1:docker-ce-cli-20.10.18-3.el7.x86_64 7/8
验证中 : docker-scan-plugin-0.17.0-3.el7.x86_64 8/8
已安装:
containerd.io.x86_64 0:1.6.8-3.1.el7 docker-ce.x86_64 3:20.10.18-3.el7 docker-ce-cli.x86_64 1:20.10.18-3.el7
作为依赖被安装:
docker-ce-rootless-extras.x86_64 0:20.10.18-3.el7 docker-scan-plugin.x86_64 0:0.17.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
完毕!
查看docker版本,默认安装最新版本
[root@docker ~]# docker -v
Docker version 20.10.18, build b40c2f6
也可以指定版本安装
查看dockers所有版本信息
[root@docker ~]# yum list docker-ce --showduplicates | sort -r
源 'zgf' 在配置文件中未指定名字,使用标识代替
已加载插件:fastestmirror
已安装的软件包
可安装的软件包
* updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64 3:20.10.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.18-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.18-3.el7 @docker-ce-stable
docker-ce.x86_64 3:20.10.17-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.16-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.15-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.14-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.13-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.12-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.15-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.14-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.13-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.aliyun.com
安装想要的版本
yum install --setopt=obsoletes=0 docker-ce-17.03.2.ce-1.el7.centos
# 如果上面命令安装不成功可以使用下面这种安装,因为可能缺失了后面的依赖包
yum install --setopt=obsoletes=0 docker-ce-18.03.0.ce-1.el7.centos docker-ce-selinux-18.03.0.ce-1.el7.centos.noarch
启动docker并设置开机自启
[root@docker ~]# systemctl enable docker --now
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
验证安装启动成功
#不报错
[root@docker ~]# docker version
Client: Docker Engine - Community
Version: 20.10.18
API version: 1.41
Go version: go1.18.6
Git commit: b40c2f6
Built: Thu Sep 8 23:14:08 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.18
API version: 1.41 (minimum version 1.12)
Go version: go1.18.6
Git commit: e42327a
Built: Thu Sep 8 23:12:21 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
#有docker0
[root@docker ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:4a:b5:43:dc txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
使用docker
从docker官网下载centos镜像
搜索名字为centos的镜像
[root@docker ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 7310 [OK]
kasmweb/centos-7-desktop CentOS 7 desktop for Kasm Workspaces 24
couchbase/centos7-systemd centos7-systemd images with additional debug… 4 [OK]
dokken/centos-7 CentOS 7 image for kitchen-dokken 3
continuumio/centos5_gcc5_base 3
dokken/centos-stream-9 2
dokken/centos-stream-8 2
spack/centos6 CentOS 6 with Spack preinstalled 1
spack/centos7 CentOS 7 with Spack preinstalled 1
dokken/centos-8 CentOS 8 image for kitchen-dokken 0
dokken/centos-6 CentOS 6 image for kitchen-dokken 0
ustclug/centos Official CentOS Image with USTC Mirror 0
bitnami/centos-extras-base 0
datadog/centos-i386 0
corpusops/centos-bare https://github.com/corpusops/docker-images/ 0
couchbase/centos-72-java-sdk 0
corpusops/centos centos corpusops baseimage 0
couchbase/centos-72-jenkins-core 0
bitnami/centos-base-buildpack Centos base compilation image 0 [OK]
fnndsc/centos-python3 Source for a slim Centos-based Python3 image… 0 [OK]
couchbase/centos-70-sdk-build 0
couchbase/centos-69-sdk-build 0
couchbase/centos-69-sdk-nodevtoolset-build 0
dokken/centos-5 EOL DISTRO: For use with kitchen-dokken, Bas… 0
spack/centos-stream 0
下载centos镜像
[root@docker ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
查看下载的centos镜像
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 12 months ago 231MB
启动centos镜像
centos为系统镜像,交互运行容器直接进入
[root@docker ~]# docker run -it centos:latest /bin/bash
[root@5ec32e206246 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@5ec32e206246 /]# exit
exit
从docker官网下载nginx镜像
搜索名字为nginx的镜像
[root@docker ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 17381 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 177
bitnami/nginx Bitnami nginx Docker Image 140 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 58
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 20 [OK]
rancher/nginx-ingress-controller 11
webdevops/nginx Nginx container 9 [OK]
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
bitnami/nginx-ldap-auth-daemon 3
rancher/nginx 2
kasmweb/nginx An Nginx image based off nginx:alpine and in… 2
vmware/nginx 2
rancher/nginx-ingress-controller-defaultbackend 2
rapidfort/nginx RapidFort optimized, hardened image for NGINX 2
bitnami/nginx-exporter 2
bitnami/nginx-intel 1
wallarm/nginx-ingress-controller Kubernetes Ingress Controller with Wallarm e… 1
vmware/nginx-photon 1
ibmcom/nginx-ingress-controller-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 0
rancher/nginx-conf 0
rancher/nginx-ssl 0
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 0
continuumio/nginx-ingress-ws 0
rancher/nginx-ingress-controller-amd64 0
ibmcom/nginx-ppc64le Docker image for nginx-ppc64le 0
下载nginx镜像
[root@docker ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
31b3f1ad4ce1: Pull complete
fd42b079d0f8: Pull complete
30585fbbebc6: Pull complete
18f4ffdd25f4: Pull complete
9dc932c8fba2: Pull complete
600c24b8ba39: Pull complete
Digest: sha256:2888a97f7c7d498bbcc47ede1ad0f6ced07d72dfd181071dde051863f1f79d7b
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
查看下载的nginx镜像
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 2d389e545974 8 hours ago 142MB
centos latest 5d0da3dc9764 12 months ago 231MB
启动nginx镜像
nginx镜像启动后为nginx服务,可启动容器后台运行,再用命令进入容器
[root@docker ~]# docker run -d nginx:latest
8f950611c9930cfa42cd316d73a8a31882789ddd433a7100184a02147a281174
[root@docker ~]# docker exec -it 8f950611c9930cfa42cd316d73a8a31882789ddd433a7100184a02147a281174 /bin/bash
root@8f950611c993:/# ls
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@8f950611c993:/# exit
exit
[root@docker ~]#
查看运行的容器
centos为系统,退出后直接停止,已停止,因此查询不显示centos
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f950611c993 nginx:latest "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 80/tcp upbeat_ishizaka
停止运行的nginx容器
centos为系统,退出后直接停止,已经停止,因此不需要再执行停止centos
[root@docker ~]# docker stop 8f950611c9930cfa42cd316d73a8a31882789ddd433a7100184a02147a281174
8f950611c9930cfa42cd316d73a8a31882789ddd433a7100184a02147a281174
#已没有容器在运行
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
查看所有的容器,不论停止还是正在运行
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f950611c993 nginx:latest "/docker-entrypoint.…" 11 minutes ago Exited (0) About a minute ago upbeat_ishizaka
5ec32e206246 centos:latest "/bin/bash" 18 minutes ago Exited (0) 16 minutes ago xenodochial_roentgen
删除停止运行的容器
[root@docker ~]# docker rm 8f950611c993
8f950611c993
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ec32e206246 centos:latest "/bin/bash" 18 minutes ago Exited (0) 16 minutes ago xenodochial_roentgen
[root@docker ~]# docker rm 5ec32e206246
5ec32e206246
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
删除镜像
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 2d389e545974 8 hours ago 142MB
centos latest 5d0da3dc9764 12 months ago 231MB
[root@docker ~]# docker rmi nginx:latest
Untagged: nginx:latest
Untagged: nginx@sha256:2888a97f7c7d498bbcc47ede1ad0f6ced07d72dfd181071dde051863f1f79d7b
Deleted: sha256:2d389e545974d4a93ebdef09b650753a55f72d1ab4518d17a30c0e1b3e297444
Deleted: sha256:363202476290a0db2316a59ad55a204a29c38a3911e3446667cb701cc4198dc7
Deleted: sha256:2206f0339ff8e4bea401bd90d6dc4e7e709bc22428c1ae5f68f38c67386c7e7f
Deleted: sha256:d70edfab07872218e08147095350ca0ae6e2b6cc21c38468b95d00e9ae8325cc
Deleted: sha256:7b46b6757c9a5142df79b3310962da6c7dd41a49a5a51c938d44fdf574b5f8e3
Deleted: sha256:39a76abc4386c54429c626f7bc0e378eddf566dad18f6b8a2281e480a5cae071
Deleted: sha256:b45078e74ec97c5e600f6d5de8ce6254094fb3cb4dc5e1cc8335fb31664af66e
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 12 months ago 231MB
[root@docker ~]#