一、安装docker
系统: centos 8 按照官网教程进行一步一步进行安装
- 删除旧的docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 下载依赖包
yum install -y yum-utils
- 配置镜像仓库
#国外的地址
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 设置阿里云的Docker镜像仓库
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 更新缓存
yum makecache
- 下载docker
yum install docker-ce docker-ce-cli containerd.io # 安装社区版
yum install docker-ee docker-ee-cli containerd.io # 安装企业版
二、遇到的问题
在下载依赖包时提示
Errors during downloading metadata for repository 'etc_yum.repos.d_':
- Curl error (37): Couldn't read a file:// file for file:///etc/yum.repos.d/repodata/repomd.xml [Couldn't open file /etc/yum.repos.d/repodata/repomd.xml]
Error: Failed to download metadata for repo 'etc_yum.repos.d_': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
于是按照错误查到:
centos8项目官方已于2021年底停止,相关源已无法使用,所以网上22年前的换源教程都已无法使用
解决问题(经过查询实践得到的可用的教程)
步骤
- 删除旧的repo文件
cd /etc/yum.repos.d/
rm rf *.reps
- 重新下载可用.repo文件
# 使用wget命令进行下载
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 没有wget命令,使用curl进行下载
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
- 从安装第一步重新执行一遍就可成功安装docker了
三. 启动docker
提示: 一般在安装成功后会自动启动
systemctl start docker #启动docker
docker version #查看版本
systemctl enable docker # 设置开机启动
测试
Hell-world
docker run hello-world
如下:
Unable to find image 'hello-world:latest' locally # 本地没有
latest: Pulling from library/hello-world # pull一个最新版
2db29710123e: Pull complete # pull成功
Digest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
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/
四. 配置阿里云镜像
进入阿里云官网找到镜像加速
执行命令
# 创建docker文件
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://8gmlkhdl.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
五. 卸载docker
yum remove docker-ce docker-ce-cli containerd.io # 卸载依赖
rm -rf /var/lib/docker # 删除资源 . /var/lib/docker是docker的默认工作路径