根据官方文档: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 ] curl# - "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: . 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
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). . 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. 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 . 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 ] 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"

分析原因为:阿里的镜像库文件也指向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#g

再执行docker的安装命令即可安装成功。

sudo yum install docker-ce

内容如下:

Installed:
docker-ce.x86_64 :18.03..ce-.el7.centos Dependency Installed:
audit-libs-python.x86_64 :2.7.-.el7 checkpolicy.x86_64 :2.5-.el7 container-selinux.noarch :2.42-.gitad8f0f7.el7 libcgroup.x86_64
libtool-ltdl.x86_64 :2.4.-.el7_3 pigz.x86_64 :2.3.-.el7.centos policycoreutils-python.x86_64 :2.5-17.1.el7 python-IPy.noarch Complete!

5.验证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-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'.

此错误也是网络问题:出现这个问题原因为国内网络问题,无法连接到 docker hub。 
配置阿里云的docker镜像库:在阿里云开通容器镜像服务拿到加速地址在执行以下命令:

也可以:

好在国内已经有  daocloud,docker指定该源即可。

vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target [Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --registry-mirror=http://f2d6cb40.m.daocloud.io
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd and above support this version.
#TasksMax=infinity
TimeoutStartSec=
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=
StartLimitInterval=60s [Install]
WantedBy=multi-user.target

重启docker服务:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

再次验证docker:

sudo docker run hello-world

出现一下内容表示验证成功:

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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. 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:
https://docs.docker.com/engine/userguide/

Centos环境docker的正确安装及疑难杂症的更多相关文章

  1. CentOS环境Docker安装教程(官方推荐的docker三种方式安装)

    CentOS环境Docker安装教程(官方推荐的docker三种方式安装) 一.使用yum方式安装 1.安装依赖包 $ sudo yum install -y yum-utils device-map ...

  2. centos环境 使用kubeadm快速安装k8s集群v1.16.2

    全程使用root用户运行,宿主机需要连接外网 浏览一下官方kubeadm[有些镜像用不了] https://kubernetes.io/docs/setup/production-environmen ...

  3. vagrant + virtualbox安装centos环境+docker安装

    1. 下载vagrant 并安装,安装完成后,输入vagrant回车查看是否安装成功 2. 下载virtualbox.box并安装,安装完成后. 3. 创建虚拟机文件夹,例如.F:/vmimg/fir ...

  4. MPSOC之3——centos环境配置及petalinux安装及使用

    ubuntu虽然能正常安装,但是build时会出现闪退情况,闪退后一切归零,没啥错误提示,改用centos来安装petalinux. 0.环境 vmware pro 14,centos 7.3 pet ...

  5. centos install docker setup centos7 安装docker

    centos7 安装docker 1: 安装必要的一些系统工具sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2: 添 ...

  6. CentOS环境下通过YUM安装软件,搭建lnmp环境

    安装nginx.php-fpm和mysql. yum install nginx yum install php-fpm yum install mysql CentOS下LNMP环境配置 1. 配置 ...

  7. centos环境下使用CPAN安装perl模块

    首先安装CPAN yum install perl-CPAN 进入cpan环境 perl -MCPAN -e shell 安装模块(以Tk为例) cpan>install Tk 退出 cpan& ...

  8. 全网最详细的大数据集群环境下如何正确安装并配置多个不同版本的Cloudera Hue(图文详解)

    不多说,直接上干货! 为什么要写这么一篇博文呢? 是因为啊,对于Hue不同版本之间,其实,差异还是相对来说有点大的,具体,大家在使用的时候亲身体会就知道了,比如一些提示和界面. 全网最详细的大数据集群 ...

  9. 自动化测试平台环境docker部署

    参考资料:testin云测 https://www.testin.cn接口自动化测试平台:http://120.79.232.23星云测试 http://www.threadingtest.com腾讯 ...

随机推荐

  1. [luogu4755]Beautiful Pair

    [luogu4755]Beautiful Pair luogu 第一次写最大值分治感觉有点丑 每次找到最大值mid,扫小的一边,主席树查大的一边小于等于\(\frac{a[mid]}{a[i]}\)的 ...

  2. python三大器

    装饰器 装饰器的作用: 装饰器的本质:一个闭包函数 (高阶函数+嵌套函数) 装饰器的功能:在不修改原函数及其调用方式的情况下对原函数功能进行扩展 闭包原理 装饰器执行流程 带多个参数函数 import ...

  3. postgres=# psql -U postgres -h 127.0.0.1 -p 5432 -d dreamstart_dev -w

    postgres=# psql -U postgres -h 127.0.0.1 -p 5432 -d dreamstart_dev -wpostgres-# \dNo relations found ...

  4. eclispse + tomcat 启动是不加载项目的解决办法

    有一个java spring的项目一直好好的,突然一天不能启动了.eclipse的console没有报任何错误,相关的server配置也没有问题,经过一翻折腾顺便还把eclipse从indigo升级到 ...

  5. c/c++ 输入输出技巧

    C: 小数的四舍五入问题 小数用 %.xf 输出的话 是会自动四舍五入的 比如说 double e = 2.718, c = 3.141; printf("%.2lf\n", e) ...

  6. 培训笔记——ubuntu安装

    1.选择安装位置,如果是做双系统提前准备一个分区,如果覆盖安装就无所谓了2.下载iso镜像文件,制作启动盘,Windows或linux环境下分别有相应的软件可以制作启动光盘或U盘3.开始安装一 设置开 ...

  7. Oracle数据库体系结构(6)数据库归档重做日志文件管理

    归档重做日志文件的概念和选择 Oracle数据库能够把已经写满了的重做日志文件保存到一个或多个指定的离线位置,这种保存的文件为归档重做日志文件.通常情况下一个归档重做日志时一个被LGWR写满的重做日志 ...

  8. Unity 中 GetComponentsInChildren 的应用

    在实际项目中,我们经常要去查找一个节点下的某个子节点,但是子节点太多,或者每次我们都要去自己写GameObject.FindChald("xxx")实在是太过繁琐,那么这是后就可以 ...

  9. Linux 上通过rpm安装mysql

    安装mysql之前要remove掉系统自带的mysql: rpm -qa | grep "MySQL*"    和rpm -qa | grep mysql  要确保卸载干净 rpm ...

  10. Hadoop切换namenode为active

    hadoop切换namenode为active 进入hadoop/bin目录下 ./yarn rmadmin -transitionToActive --forcemanual rm1 重新启动zkf ...