官网安装参考手册:https://docs.docker.com/install/linux/docker-ce/centos/
检测CentOS版本:7以上
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 8.5.2111
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# yum -y install:安装 -y:所有提示都为y
yum -y install 包名
环境:
yum -y install gcc
yum -y install gcc-c++
工具:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
等价于
sudo yum install -y yum-utils
sudo yum -y install device-mapper-persistent-data
sudo yum -y install lvm2
官方镜像:(比较慢,不推荐)
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
阿里镜像仓库 :(推荐)
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
sudo yum install docker-ce docker-ce-cli containerd.io
冲突使用:
(尝试在命令行中添加 ‘–allowerasing’ 来替换冲突的软件包 或 ‘–skip-broken’ 来跳过无法安装的软件包 或 ‘–nobest’ 来不只使用软件包的最佳候选)
yum install docker-ce docker-ce-cli containerd.io --allowerasing
包含compose
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin --allowerasing
systemctl enable docker
systemctl start docker
查看docker服务状态:
systemctl status docker.service
[root@localhost ~]# docker -v
Docker version 20.10.21, build baeda1f
docker默认存储路径是/var/lib/docker,占用服务器根分区。容易导致磁盘空间占满。
本文介绍通过system下修改配置文件,直接在配置文件中配置新的docker存储路径进行修改。
mkdir -p /data/dockerdata/docker
cp -r /var/lib/docker /data/dockerdata
vim /lib/systemd/system/docker.service
在ExecStart参数里加入:
--graph=/data/dockerdata/docker
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
docker version
docker run hello-world
docker images
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://0b27f0a81a00f3560fbdc00ddd2f99e0.mirror.swr.myhuaweicloud.com",
"https://ypzju6vq.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl stop docker
sudo yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd