docker 入门教程(安装)

本文详细介绍了在CentOS8系统上安装Docker的过程,包括删除旧版本、设置阿里云镜像仓库、解决下载依赖包时的错误、启动和测试Docker,以及配置阿里云镜像加速器。在安装过程中,由于CentOS8官方源已停用,文章提供了使用阿里云镜像源的解决方案,并给出了卸载Docker的步骤。
摘要由CSDN通过智能技术生成


一、安装docker

系统: centos 8 按照官网教程进行一步一步进行安装

  1. 删除旧的docker
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
  1. 配置镜像仓库
#国外的地址
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
  1. 更新缓存
yum makecache
  1. 下载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年前的换源教程都已无法使用

解决问题(经过查询实践得到的可用的教程)

步骤

  1. 删除旧的repo文件
cd /etc/yum.repos.d/
rm rf *.reps
  1. 重新下载可用.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
  1. 从安装第一步重新执行一遍就可成功安装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的默认工作路径
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值