Centos7.9安装Docker

Centos7.9安装Docker

𝓓𝓸𝓷 Lv6

一、关闭防火墙

1
2
3
systemctl stop firewalld  
systemctl disable firewalld
systemctl status firewalld

二、关闭selinux

1
2
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux  
setenforce 0

三、配置本地yum源(可选)

本地yum源安装Docker版本太低,安装可能会失败,可以配置阿里yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat  > /etc/yum.repos.d/CentOS-Base.repo <<EOF

[base]
name=CentOS-\$releasever - Base
baseurl=file:///mnt
gpgcheck=0
enabled=1

EOF


mount -o loop /opt/soft/CentOS-7-x86_64-DVD-2009.iso /mnt

yum clean all && yum makecache

四、配置阿里yum源

1
2
3
4
5
6
7
cd /etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum install epel-release -y
yum install container-selinux -y #安装最新的contain-selinux

yum clean all && yum makecache

五、移除旧版Docker

1
2
3
4
5
6
7
8
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

六、安装依赖工具

1
yum install -y yum-utils device-mapper-persistent-data lvm2

七、设置Docker稳定仓库

1
2
3
4
5
6
7
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

yum makecache fast

八、安装Docker Engine(社区版)

1
2
3
4
5
6
yum install docker-ce docker-ce-cli containerd.io


安装报错:
containerd.io-1.6.33-3.1.el7.x86_64: [Errno 256] No more mirrors to try.
一般是网络不稳定引起的,重新安装即可

九、启动Docker

1
2
3
systemctl start docker
systemctl status docker
systemctl enable docker

十、验证Docker

1
2
3
docker -v
docker run hello-world
docker info

十一、镜像加速

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cat  >  /etc/docker/daemon.json  << EOF

{
"registry-mirrors": [
"https://docker-0.unsee.tech",
"https://docker.1ms.run",
"https://docker.xuanyuan.me",
"https://0vrv861z.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]

}

EOF

十二、重启Docker

1
systemctl restart docker

十三、修改Docker默认存储位置

1.停止Docker
1
2
3
4
5
6
7
systemctl stop docker

Warning: Stopping docker.service, but it can still be activated by:
docker.socket
解决方法:
systemctl status docker.socket
systemctl stop docker.socket
2.查看Docker存储目录位置
1
2
3
docker info|grep -i root

Docker Root Dir: /var/lib/docker
3.创建新的存储路径
1
mkdir /opt/docker
4.将数据迁移至新的存储路径
1
2
3
4
5
6
7
8
rsync -av --progress /var/lib/docker/* /opt/docker/

也可以使用mv命令移动文件,rsync命令更安全

rsync参数:
-a 表示归档模式,保持文件的权限、时间戳等信息。
-v 表示显示详细的输出。
--progress 显示进度。
5.修改Docker配置文件

添加 “data-root”: “/opt/docker”参数,注意参数后面有逗号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
vi /etc/docker/daemon.json

{
"data-root": "/opt/docker",
"registry-mirrors": [
"https://docker-0.unsee.tech",
"https://docker.1ms.run",
"https://docker.xuanyuan.me",
"https://0vrv861z.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
"https://docker.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://your_preferred_mirror",
"https://dockerhub.icu",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]

}
6.重启Docker
1
2
systemctl daemon-reload
systemctl start docker
7.验证 Docker 存储目录
1
docker info|grep -i root
8.删除旧的Docker数据文件
1
rm -rf /var/lib/docker

十四、日常查询

1.查看docker容器资源使用情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# docker stats

CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
6e61c1f01f08 yhis-material-center-test.1.tx0hi3nbp57743mrd1gtcff8b 3.40% 620.8MiB / 22.63GiB 2.68% 153MB / 169MB 22.9GB / 0B 300
586420293fb0 yhis-financial-center-test.1.ti5q290tk75nhu8jdcs50rkau 6.51% 1.064GiB / 22.63GiB 4.70% 1.22GB / 1.43GB 200GB / 0B 368
80d8f448756e yhis-platform-maindata-test.1.pdh2ofd7hu145zhni2rmh6qm9 5.74% 620.5MiB / 22.63GiB 2.68% 2.9GB / 3.34GB 62.9GB / 0B 340
5e2d1220ec33 yhis-visit-inp-test.1.yz8bejyotxvsobwy76z9ijs25 4.53% 731.3MiB / 22.63GiB 3.16% 837MB / 816MB 242GB / 0B 311
88b38dc5b86d yhis-query-statistics-test.1.31eclqtv8sgqv6njkmp7xcdis 4.40% 567.8MiB / 22.63GiB 2.45% 673MB / 759MB 299GB / 0B 299
79acf5452821 yhis-patient-center-test.1.w7owsmq78hg8bhsy56tdqqsgd 3.88% 604.5MiB / 22.63GiB 2.61% 691MB / 752MB 241GB / 0B 309
428170600f20 yhis-encounter-center-test.1.n6uhk2ebljcvz5imyunicd61s 4.29% 680.4MiB / 22.63GiB 2.94% 724MB / 800MB 269GB / 0B 321
b8e447635d03 yhis-clinic-surgery-test.1.qfrrty4mabqpnt3c4ofh2zaln 4.33% 662.6MiB / 22.63GiB 2.86% 684MB / 745MB 234GB / 0B 296
b33b384e92a7 yhis-platform-system-test.1.rpxfd4hriiddpx8c9ib6r424u 4.92% 555.4MiB / 22.63GiB 2.40% 931MB / 987MB 212GB / 0B 308
2d9be232774d yhis-financial-center-inp-test.1.mo7ppo3e13yhxv931yhw4d1sk 5.16% 725.4MiB / 22.63GiB 3.13% 821MB / 992MB 321GB / 0B 388
42eab630962e yhis-clinic-nurse-test.1.hxvnl8yaq1kp038trwn61owy8 5.76% 543.8MiB / 22.63GiB 2.35% 847MB / 879MB 324GB / 0B 348
f78b31421cb1 yhis-platform-file-test.1.ksa5yvgfm96fwrwr7q9faczw4 0.21% 165.8MiB / 22.63GiB 0.72% 807MB / 879MB 385GB / 0B 158
5800426a630f yhis-disease-rc-test.1.m624a2kk5fui87eix0l2u1aex 4.53% 666.1MiB / 22.63GiB 2.87% 2GB / 2.21GB 1.14TB / 0B 293
6fee2382852e xxl-job 0.44% 414.4MiB / 22.63GiB 1.79% 18GB / 12.4GB 609GB / 0B 78
0e9528bd492b seata-server 0.97% 425.2MiB / 22.63GiB 1.83% 0B / 0B 929GB / 0B 150
744018672d46 tidb 14.70% 3.844GiB / 22.63GiB 16.99% 27.6GB / 50.9GB 272TB / 25.4GB 21
39b50dfd5154 minio 3.93% 275.4MiB / 22.63GiB 1.19% 0B / 0B 14.5TB / 12.7GB 13
3ca946ec53e4 portainer 0.04% 24.88MiB / 22.63GiB 0.11% 526GB / 471GB 3.8TB / 582GB 12
03df6cf119b9 hosa-system-svc.1.sh5ld39yjvx7cb2bqhuxom8zs 347.38% 999.3MiB / 22.63GiB 4.31% 12.4kB / 14.2kB 118MB / 0B 54

2.查看镜像、容器空间使用情况
1
2
3
4
5
# docker system df -v

Images space usage:
Containers space usage:
Local Volumes space usage:
  • Title: Centos7.9安装Docker
  • Author: 𝓓𝓸𝓷
  • Created at : 2026-03-01 10:42:49
  • Updated at : 2026-04-01 16:25:39
  • Link: https://www.zhangdong.me/centos-docker-installation.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论