nics 发表于 2019-2-20 08:40:27

Centos7五步安装Docker并解决docker官方镜像无法访问问题

Centos7五步安装Docker并解决docker官方镜像无法访问问题
  根据官方文档:https://docs.docker.com/install/linux/docker-ce/centos/搭建docker
1.卸载docker旧版本:
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine123456789102.安装相关工具类:
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm21233.配置docker仓库:
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo会报以下错误:
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repograbbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repoCould not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: curl#35 - "TCP connection reset by peer12345678910这是由于国内访问不到docker官方镜像的缘故
可以通过aliyun的源来完成:
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo出现以下内容则表示docker仓库配置成功:
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repograbbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.reporepo saved to /etc/yum.repos.d/docker-ce.repo1234564.安装docker
sudo yum install docker-ce
出现以下异常:
Loaded plugins: fastestmirror
base
https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: curl#35 - "TCP connection reset by peer"Trying other mirror.

One of the configured repositories failed (Docker CE Stable - x86_64), and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:   1. Contact the upstream for the repository and get them to fix the problem.   2. Reconfigure the baseurl/etc. for the repository, to point to a working
      upstream. This is most often useful if you are using a newer
      distribution release than is supported by the repository (and the
      packages for the previous distribution release still work).   3. Run the command with the repository temporarily disabled
            yum --disablerepo=docker-ce-stable ...
   4. Disable the repository permanently, so yum won't use it by default. Yum
      will then just ignore the repository until you permanently enable it
      again or use --enablerepo for temporary usage:
            yum-config-manager --disable docker-ce-stable
      or
            subscription-manager repos --disable=docker-ce-stable
   5. Configure the failing repository to be skipped, if it is unavailable.
      Note that yum will try to contact the repo. when it runs most commands,
      so will have to try and fail each time (and thus. yum will be be much
      slower). If it is a very temporary problem though, this is often a nice
      compromise:
            yum-config-manager --save --setopt=docker-ce-stable.skip_if_unavailable=truefailure: repodata/repomd.xml from docker-ce-stable: No more mirrors to try.
https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: curl#35 - "TCP connection reset by peer"12345678910111213141516171819202122232425262728293031323334353637383940分析原因为:阿里的镜像库文件也指向docker官方库,所以需要修改库文件
sudo vim /etc/yum.repos.d/docker-ce.repo通过命令把https://download-stage.docker.com替换为http://mirrors.aliyun.com/docker-ce
命令如下:
:%s#https://download-stage.docker.com#http://mirrors.aliyun.com/docker-ce#g1234在执行安装docker的部分妈可安装成功。
sudo yum install docker-ce
内容如下:Installed:
docker-ce.x86_64 0:18.03.0.ce-1.el7.centosDependency Installed:
audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7   container-selinux.noarch 2:2.42-1.gitad8f0f7.el7 libcgroup.x86_64 0
libtool-ltdl.x86_64 0:2.4.2-22.el7_3   pigz.x86_64 0:2.3.3-1.el7.centos policycoreutils-python.x86_64 0:2.5-17.1.el7   python-IPy.noarchComplete!123456789105.验证docker安装成功:
启动docker:
sudo systemctl start docker
验证docker:
sudo docker run hello-world
则会出现以下异常:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world9bb5a5d4561a: Pulling fs layer
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18e
See 'docker run --help'.12345678910此错误也是网络问题:国内无法访问dockerhub
配置阿里云的docker镜像库:在阿里云开通容器镜像服务拿到加速地址在执行以下命令:
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json
页: [1]
查看完整版本: Centos7五步安装Docker并解决docker官方镜像无法访问问题