centos7安装docker并配置镜像

1.配置ali的yum镜像源

1. 获取阿里云 repo

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#下面两条命令如果执行报错可以直接跳过执行2
cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.清理原来的缓存,重新缓存

yum clean all

yum makecache

3.1卸载旧版本的docker

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
                  
#若之前没有安装过docker,会提示一堆不匹配,是正常现象,直接往下执行就好

3.2下载所需的安装包

yum install -y yum-utils

3.3设置镜像仓库

# 设置阿里云的Docker镜像仓库
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

3.4更新yum软件包索引

yum makecache fast

3.5安装docker相关的配置

 yum install docker-ce docker-ce-cli containerd.io

4.启动docker

systemctl start docker
# 查看当前版本号,是否启动成功
docker version
# 设置开机自启动
systemctl enable docker

5.run hello-world

docker run hello-world

你可能感兴趣的:(linux,docker,linux,centos)