Centos7 installs docker in five steps and solves the problem that the official image of docker cannot be accessed

According to official documents: https://docs.docker.com/install/linux/docker-ce/centos/ Build docker
1. Uninstall the old version of docker:

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \

2. Installation related tools:

sudo yum install -y yum-utils \
  device-mapper-persistent-data \

3. Configure the docker warehouse:

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo will report the following error:
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: [Errno 14] curl#35 - "TCP connection reset by peer12345678910

This is because the official image of docker cannot be accessed in China
You can do this through aliyun's source:

sudo yum-config-manager --add-repo http://The following content in mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo indicates that the docker warehouse configuration is successful:
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.repo123456

4. Install docker

sudo yum install docker-ce
//The following exception occurred:
Loaded plugins: fastestmirror
https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] 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
            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

            yum-config-manager --save --setopt=docker-ce-stable.skip_if_unavailable=truefailure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try.
https://download-stage.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#35 - "TCP connection reset by peer"12345678910111213141516171819202122232425262728293031323334353637383940

The analysis reason is: Alibaba's image library file also points to the official docker library, so the library file needs to be modified

sudo vim / etc/yum.repos.d/docker-ce.repo replace https://download-stage.docker.com with http://mirrors.aliyun.com/docker-ce by command
 The command is as follows:

The installation of docker is successful.

sudo yum install docker-ce
//The content is as follows: 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!12345678910

5. Verify that docker is installed successfully:

start-up docker: 
sudo systemctl start docker
//Verify docker:
sudo docker run hello-world
//The following exceptions will occur:
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

This error is also a network problem: unable to access dockerhub in China
Configure Alibaba cloud's docker image library: when you get the acceleration address after opening the container image service in Alibaba cloud, execute the following command:

sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": ["https://(own code). mirror.aliyuncs.com "]
EOFsudo systemctl daemon-reloadsudo systemctl restart docker12345678

Verify docker again:

sudo docker run hello-world
//The following indicates a successful installation:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
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:

Tags: Linux Docker yum CentOS sudo

Posted on Wed, 04 Dec 2019 15:33:22 -0800 by yankeefan238