解决Centos7安装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-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

会报以下错误:

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

这是由于国内访问不到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.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

出现以下异常:

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),
 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=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"

重启服务,查看服务状态

在CentOS 7上安装Docker并修改Docker,可以按照以下步骤进行操作: 1. 首先,卸载旧版本的Docker(如果有)。可以使用以下命令完成卸载: ``` $ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine ``` 2. 接下来,安装Docker Engine - Community。首先,准备相关工具包: ``` $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` 3. 设置Docker稳定版的YUM: ``` $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo ``` 4. 安装Docker Engine - Community。通过以下命令来安装指定版本的Docker: ``` $ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io ``` 在上述命令中,将`<VERSION_STRING>`替换为你想要安装Docker版本号。可以使用以下命令查询可用的Docker版本: ``` $ yum list docker-ce --showduplicates | sort -r ``` 5. 安装完成后,启动Docker服务: ``` $ sudo systemctl start docker ``` 6. 验证Docker服务是否成功启动: ``` $ sudo docker run hello-world ``` 7. 进行Docker的修改。默认情况下,Docker使用官方的国外镜像。如果需要更换为国内镜像,可以编辑`/etc/docker/daemon.json`文件,并添加以下内容: ``` { "registry-mirrors": ["https://<your-registry-mirror>"] } ``` 将`<your-registry-mirror>`替换为你选择的国内镜像地址。 8. 修改完成后,重新启动Docker服务: ``` $ sudo systemctl restart docker ``` 通过以上步骤,你就可以在CentOS 7上成功安装Docker并修改Docker了。请注意,在步骤7中,你可以选择使用适合你的国内镜像地址。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [CentOS 7 安装 Docker ~ 并更换国内。](https://blog.csdn.net/lyfGeek/article/details/105321231)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值