在没有配置yum源的情况下在linux系统中安装docker

阿里云YUM源配置方法

1.先将/etc/yum.repos.d/CentOS-Base.repo 中的文件备份一个(待会会重新下载一次的)

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

  1. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

  1. 运行 yum makecache 生成缓存
yum makecache

centos-7 联网安装docker

中文免费手册 [Docker — 从入门到实践]

  1. 卸载旧版
sudo yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine
  1. 安装一组工具
  sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
  1. 设置 yum 仓库地址一个是官方的一个是阿里云的
#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
  1. 更新 yum 缓存
sudo yum makecache fast
  1. 安装新版 docker
sudo yum install docker-ce docker-ce-cli containerd.io
  1. 启动 docker
sudo systemctl restart docker
  1. 设置 docker 开机启动
sudo systemctl enable docker
  1. 运行 hello-world 镜像,验证 docker(这里可能报错不要急是因为网速的问题,看第9步)
sudo docker run hello-world
  1. 镜像加速修改
vim /etc/docker/daemon.json

添加

{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] 
}
  1. 是修改生效
sudo systemctl daemon-reload
  1. 重新启动docker服务
sudo systemctl restart docker

12.重新验证hello-world

sudo docker run hello-world

成功就如下图:
在这里插入图片描述
参考文章:
阿里云开发社区
docker 安装完成后测试hello-world出现问题
CentOS – 配置docker官方源并用yum安装docker

发布了9 篇原创文章 · 获赞 0 · 访问量 174

猜你喜欢

转载自blog.csdn.net/weixin_45482334/article/details/104675399