根据官方文档: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 onlysafe 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 workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=docker-ce-stable ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable docker-ce-stableorsubscription-manager repos --disable=docker-ce-stable5. 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 muchslower). If it is a very temporary problem though, this is often a nicecompromise: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"

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

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 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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=3
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:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

转载于:https://www.cnblogs.com/liuyansheng/p/9203134.html

Centos环境docker的正确安装及疑难杂症相关推荐

  1. Python--安装pyecharts包,anaconda环境下如何正确安装神奇可视化pyecharts包[安装的那些事儿]

    Python--安装pyecharts包,anaconda环境下如何正确安装神奇可视化pyecharts包[安装的那些事儿] 更多更多安装教程及软件获取请加关注留言哟~~,若需私信联系博主请加: 一. ...

  2. Centos下docker/docker-compose离线安装

    Centos下docker离线安装 在内网环境下,一般不能联网能在线部署,这时候就需要以离线的方式安装docker.本节内容主要总结记录离线安装docker的步骤. 下载docker安装包 官方地址: ...

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

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

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

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

  5. 计算机教室要配备空调吗,教室里不安装空调吗?如何正确安装空调?

    很多城市的小学和中学的教师里都没安装空调,对于冬季取暖和夏季乘凉这个问题来说对于学生以及家长们来说都是很关心的问题.那么教室里不安装空调吗,这个问题还是各持己见的.那么需要不需要安装空调还是需要根据小 ...

  6. centos7 docker安装_教你如何在 CentOS 7 下 yum 方式安装 Docker 环境

    记录在CentOS 7下使用yum方式安装Docker环境的步骤. 1.移除旧版本: yum remove docker \                  docker-client \      ...

  7. mac桌面版安装docker并安装centos环境

    1.访问https://www.docker.com/products/docker-desktop,并点击下载,然后安装结束. 2.安装完成后在启动台打开docker,并输入docker versi ...

  8. centos 7 Docker 安装及配置镜像加速

    centos 7 Docker 安装及配置镜像加速 文章目录 centos 7 Docker 安装及配置镜像加速 Docker 版本 基于 `CentOS `安装 `Docker` 引擎 系统要求 卸 ...

  9. centos 7 java安装路径_Linux CentOS 7.0中java安装与配置环境变量的步骤详解

    一.前言: CentOS7.0虽然自带JDK1.7和1.8,运行"java -version"命令也可以看到版本信息,但是jdk的安装环境不全,比如缺少tool.jar和dt.ja ...

最新文章

  1. 京东11·11:撬动数据中心的支点——京东阿基米德
  2. 分享:嵌入式Linux入门学习指导
  3. linux QT 结束当前进程_Qt编写控件属性设计器7-串口采集
  4. python读单行文本求平均值_如何从文本文件python中的数字列表中找到平均值
  5. php4 apache 配置,[开发环境配置]windows下php4+mysql4+apache2开发环境配置
  6. java json.tostring,idea以JSON形式重写toString()方法
  7. firework.js
  8. C语言化简根号(非sqrt)
  9. mysql 外键约束失败_MYSQL:错误:无法添加或更新子行:外键约束失败
  10. linux 流量控制
  11. html5能调用手机陀螺仪么,详解html5如何获取手机陀螺仪角度信息的示例代码
  12. word(2010)使用VBA完成批处理操作-批量清除表格某单元格内容
  13. 红米5plus刷android one,手机知识:红米5plus如何 红米5plus配置参数
  14. 用Qt写一个简单的音乐播放器(三):增加界面(播放跳转与音量控制)
  15. TypeScript真香系列-高级类型
  16. 使用代理爬去微信公众号_手游推广,手游折扣代理,微信视频号这个引流方式的使用...
  17. 堆在计算机中的作用,堆(数据结构)_百度百科
  18. 计算机出国培训,新海岸出国
  19. Filter过滤器url-pattern的两种方式
  20. JAVA求是否能够构成内切圆_Java编程 如何计算三角形的内切圆半径?

热门文章

  1. 蓝书4.1-4.4 树状数组、RMQ问题、线段树、倍增求LCA
  2. Bootstrap4 网格系统
  3. 【咸鱼教程】基于系统时间的计时器DateTimer(不受FPS影响)
  4. HDU 2896 病毒侵袭 AC自动机
  5. 十一. 图形、图像与多媒体1.绘图基础
  6. windows根据端口号找进程
  7. 引领潮流云电视机遇与挑战并现
  8. html长文本自动换行
  9. wp7 sdk部署应用操作
  10. 3-3 面向对象 本章总结