linux值centos7安装docker
1,卸载旧版本
$ yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2,需要的安装包
[root@localhost roo]# yum install -y yum-utils
这一步可以yum可能报错,如果报错了,执行下面的语句,没问题这不用执行
[root@localhost roo]# rm -f /var/run/yum.pid
3,设置镜像仓库
[root@localhost roo]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4,安装docker相关
[root@localhost roo]# sudo yum install docker-ce docker-ce-cli containerd.io
5,启动docker
[root@localhost roo]# system start docker
6,查看是否安装成功
[root@localhost roo]# systemctl start docker
7,执行hello-word
[root@localhost roo]# docker run hello-world
说明安装成功
8,查看一下镜像
[root@localhost roo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 11 months ago 13.3kB
9,卸载(一般不用)
1,卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
2、删除镜像/容器等
rm -rf /var/lib/docker
10,阿里云加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://9xj7kbt8.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
无用,做时代码
[root@localhost roo]# rm -f /var/run/yum.pid
[root@localhost roo]# yum install -y yum-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-53.el7 将被 升级
---> 软件包 yum-utils.noarch.0.1.1.31-54.el7_8 将被 更新
--> 解决依赖关系完成
依赖关系解决
============================================================================================================================================
Package 架构 版本 源 大小
============================================================================================================================================
正在更新:
yum-utils noarch 1.1.31-54.el7_8 base 122 k
事务概要
============================================================================================================================================
升级 1 软件包
总下载量:122 k
Downloading packages:
No Presto metadata available for base
警告:/var/cache/yum/x86_64/7/base/packages/yum-utils-1.1.31-54.el7_8.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY:00 ETA
yum-utils-1.1.31-54.el7_8.noarch.rpm 的公钥尚未安装
yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:07
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
软件包 : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : yum-utils-1.1.31-54.el7_8.noarch 1/2
清理 : yum-utils-1.1.31-53.el7.noarch 2/2
验证中 : yum-utils-1.1.31-54.el7_8.noarch 1/2
验证中 : yum-utils-1.1.31-53.el7.noarch 2/2
更新完毕:
yum-utils.noarch 0:1.1.31-54.el7_8
完毕!
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# 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
[root@localhost roo]# yum makecache fast
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.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
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/x86_64/primary_db | 50 kB 00:00:00
元数据缓存已建立
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# sudo yum install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.4.3-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.4.3-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.20.10.0-3.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-20.10.0-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.0-3.el7 将被 安装
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.0-3.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-20.10.0-3.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-20.10.0-3.el7.x86_64 需要
--> 正在检查事务
---> 软件包 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.4.3-3.1.el7 docker-ce-stable 33 M
docker-ce x86_64 3:20.10.0-3.el7 docker-ce-stable 27 M
docker-ce-cli x86_64 1:20.10.0-3.el7 docker-ce-stable 33 M
为依赖而安装:
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
docker-ce-rootless-extras x86_64 20.10.0-3.el7 docker-ce-stable 9.0 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 依赖软件包)
总下载量:102 M
安装大小:420 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:03
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.0-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-ce-20.10.0-3.el7.x86_64.rpm 的公钥尚未安装
(2/8): docker-ce-20.10.0-3.el7.x86_64.rpm | 27 MB 00:01:23
(3/8): containerd.io-1.4.3-3.1.el7.x86_64.rpm | 33 MB 00:01:44
(4/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:01
(5/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:03
(6/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:04
(7/8): docker-ce-rootless-extras-20.10.0-3.el7.x86_64.rpm | 9.0 MB 00:00:26
(8/8): docker-ce-cli-20.10.0-3.el7.x86_64.rpm | 33 MB 00:01:16
--------------------------------------------------------------------------------------------------------------------------------------------
总计 648 kB/s | 102 MB 00:02:40
从 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
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/8
正在安装 : containerd.io-1.4.3-3.1.el7.x86_64 2/8
正在安装 : 1:docker-ce-cli-20.10.0-3.el7.x86_64 3/8
正在安装 : slirp4netns-0.4.3-4.el7_8.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
正在安装 : docker-ce-rootless-extras-20.10.0-3.el7.x86_64 7/8
正在安装 : 3:docker-ce-20.10.0-3.el7.x86_64 8/8
验证中 : 3:docker-ce-20.10.0-3.el7.x86_64 1/8
验证中 : fuse3-libs-3.6.1-4.el7.x86_64 2/8
验证中 : fuse-overlayfs-0.7.2-6.el7_8.x86_64 3/8
验证中 : slirp4netns-0.4.3-4.el7_8.x86_64 4/8
验证中 : docker-ce-rootless-extras-20.10.0-3.el7.x86_64 5/8
验证中 : 1:docker-ce-cli-20.10.0-3.el7.x86_64 6/8
验证中 : containerd.io-1.4.3-3.1.el7.x86_64 7/8
验证中 : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 8/8
已安装:
containerd.io.x86_64 0:1.4.3-3.1.el7 docker-ce.x86_64 3:20.10.0-3.el7 docker-ce-cli.x86_64 1:20.10.0-3.el7
作为依赖被安装:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-ce-rootless-extras.x86_64 0:20.10.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
完毕!
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# system start docker
bash: system: 未找到命令...
[root@localhost roo]# systemctl start docker
[root@localhost roo]# docker --version
Docker version 20.10.0, build 7287ab3
[root@localhost roo]# docker version
Client: Docker Engine - Community
Version: 20.10.0
API version: 1.41
Go version: go1.13.15
Git commit: 7287ab3
Built: Tue Dec 8 18:57:35 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.0
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: eeddea2
Built: Tue Dec 8 18:56:55 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@localhost roo]# docker image
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
[root@localhost roo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost roo]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
Status: Downloaded newer image for hello-world:latest
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 roo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 11 months ago 13.3kB
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# sudo mkdir -p /etc/docker
[root@localhost roo]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://9xj7kbt8.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://9xj7kbt8.mirror.aliyuncs.com"]
}
[root@localhost roo]# sudo systemctl daemon-reload
[root@localhost roo]# sudo systemctl restart docker
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# sudo mkdir -p /etc/docker
[root@localhost roo]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:5dff:fe8c:fc24 prefixlen 64 scopeid 0x20<link>
ether 02:42:5d:8c:fc:24 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 1483 (1.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.186 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::d28d:6577:32f3:4db8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:8c:77:e4 txqueuelen 1000 (Ethernet)
RX packets 586110 bytes 852710431 (813.2 MiB)
RX errors 0 dropped 23 overruns 0 frame 0
TX packets 314530 bytes 20889649 (19.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 208 bytes 17760 (17.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 208 bytes 17760 (17.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:90:32:9d txqueuelen 1000 (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
[root@localhost roo]#
[root@localhost roo]#
[root@localhost roo]# docker version
Client: Docker Engine - Community
Version: 20.10.0
API version: 1.41
Go version: go1.13.15
Git commit: 7287ab3
Built: Tue Dec 8 18:57:35 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.0
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: eeddea2
Built: Tue Dec 8 18:56:55 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@localhost roo]# docker image
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
[root@localhost roo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 11 months ago 13.3kB
[root@localhost roo]# docker pull composer
Using default tag: latest
latest: Pulling from library/composer
188c0c94c7c5: Pull complete
45f8bf6cfdbe: Pull complete
ce5be7974012: Pull complete
a99dd6507fe5: Pull complete
11c513a1b503: Pull complete
ff080eafb4c0: Pull complete
e818119992b1: Pull complete
cba3c14a67f9: Pull complete
fbb0285b7ad2: Pull complete
0e1df8dc2247: Pull complete
8b920d7e816e: Pull complete
0751062e31d2: Pull complete
dfa78ab21f7e: Pull complete
51566da670a3: Pull complete
1b5de5d9a22a: Pull complete
Digest: sha256:dde179e850cc8bb5817922994f423cc7e66971df90c1e727b68df8f2f2d52333
Status: Downloaded newer image for composer:latest
docker.io/library/composer:latest
[root@localhost roo]#
[root@localhost roo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
composer latest 4eb9c84dfcfe 7 days ago 176MB
hello-world latest bf756fb1ae65 11 months ago 13.3kB
[root@localhost roo]# ^C
[root@localhost roo]#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构