1. ホーム
  2. ドッカー

Centos7 5つのステップでDockerをインストールし、公式Dockerイメージにアクセスできない問題を解決します。

2022-03-03 22:57:56
<パス

公式ドキュメントによると 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-engine

2. 関連するツールクラスをインストールします。

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

3. docker リポジトリを設定します。

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
The following error will be reported.
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
Could 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 peer


これは、公式のドッカーイメージが国内ではアクセスできないことに起因しています
のaliyunのソースを経由して行うことができます。

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
A successful docker repository configuration is indicated by the following.
Loaded plugins: fastestmirror
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

4. dockerのインストール

sudo yum install docker-ce
The following exception occurs.
Loaded plugins: fastestmirror
base
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),
 One of the configured repositories failed (Docker CE Stable - x86_64), and yum doesn't have enough cached data to continue.
 There are a few ways to work "fix" this:

     Contact the upstream for the repository and get them to fix the problem.

     Reconfigure the baseurl/etc. for the repository, to point to a working
        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).

     Run the command with the repository temporarily disabled
            yum --disablerepo=docker-ce-stable ...

     Disable the repository permanently, so yum won't use it by default.
        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

     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,
        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 much
        yum will be much slower). If it is a very temporary problem though, this is often a nice
        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=true

failure: 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 "

その理由は、Aliのイメージライブラリファイルも公式のDockerライブラリを指しているため、ライブラリファイルを修正する必要があるためです

sudo vim /etc/yum.repos.d/docker-ce.repo
Put https://download-stage.docker.com替换为http://mirrors.aliyun.com/docker-ce through the command
command as follows.
:%s#https://download-stage.docker.com#http://mirrors.aliyun.com/docker-ce#g

install dockerの部分を実行すると、momが正常にインストールできるようになります。

sudo yum install docker-ce
The content is as follows.
Installed:
  docker-ce.x86_64 0:18.03.0.ce-1.el7.centos

Dependency 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.noarch

Complete!


5. dockerのインストールが成功したことを確認します。

Start docker.
sudo systemctl start docker
Verify docker:
sudo docker run hello-world
The following exception will be thrown.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: 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'.

このエラーはネットワークの問題でもあります:dockerhubは国内からアクセスできません
Aliyunのdockerイメージリポジトリの設定:以下のコマンドを実行する前に、Aliunでコンテナイメージサービスを開き、アクセラレーションアドレスを取得します。

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://{self-encoded}.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

もう一度dockerを検証します。

sudo docker run hello-world
A successful installation is indicated by the following.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: 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.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 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: