centos7安装docker-ce&拉取公网镜像教程

centos7安装docker-ce教程

配置系统环境代理

  • vi /root/.bashrc 加代理配置:
export http_proxy=http://xxx域名:端口
export https_proxy=http://xxx域名:端口
  • 使配置生效
source .bashrc

配置yum自身代理

  • vi /etc/yum.conf 加代理配置:
proxy=http://xxx域名:端口

切yum源,换成163的

  • 目录:/etc/yum.repos.d/
    首先备份源(如果本身/etc/yum.repos.d/这个目录下没有,就不用备份):
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  • 下载163源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

修改其文件名

mv CentOS7-Base-163.repo CentOS-Base.repo
  • 刷新YUM的缓存状态:
yum clean all
yum makecache

注:报错,执行yum-config-manager --disable remote

卸载已经安装的docker

  • 查询:yum list installed | grep docker
  • 删除:yum -y remove 软件包名

安装docker-ce

  • yum install -y yum-utils device-mapper-persistent-data lvm2 --必须安装的两个软件包yum-utils,device-mapper-persistent-data lvm2
    注意:安装yum-utils,它提供一个yum-config-manager单元,同时安装的device-mapper-persistent-data和lvm2用于储存设备映射(devicemapper)必须的两个软件包
  • yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • yum install docker-ce --默认安装最新版本
    注意

安装指定版本的方式

  1. yum list docker-ce --showduplicates | sort -r --查看有哪些版本
  2. sudo yum install docker-ce- --安装指定版本的

启动服务

  • systemctl start docker --启动docker服务

Centos7 通过proxy 使用docker pull 镜像

  1. 创建目录
    mkdir /etc/systemd/system/docker.service.d
  2. 创建配置文件
    touch /etc/systemd/system/docker.service.d/http-proxy.conf
  3. 编辑文件并加入以下内容
    vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://ip:port"

4.更新重加载配置&重启Docker服务

systemctl daemon-reload
systemctl stop docker
systemctl start docker

你可能感兴趣的:(centos7安装docker-ce&拉取公网镜像教程)