设为首页 收藏本站
查看: 1341|回复: 0

[经验分享] centos7上安装docker-ce社区版

[复制链接]

尚未签到

发表于 2017-12-7 06:36:30 | 显示全部楼层 |阅读模式
报错:Error: docker-ce-selinux conflicts with 2:container-selinux-2.12-2.gite7096ce.el7.noarch

转载:http://abloz.com/tech/2017/06/06/centos7-docker-installation/

概述
  本文是centos7上安装docker-ce社区版的最新稳定版的实录.
  docker-ce最新稳定版需要linux kernel 大于3.10.
  可以用如下的程序来检查兼容性.



curl https://raw.githubusercontent.com/docker/docker/master/contrib/check-config.sh > check-config.sh
bash ./check-config.sh

  对其他操作系统和版本,可以参考官方文档.

安装相关依赖
  yum-utils 提供 yum-config-manager 工具, devicemapper存储驱动依赖 device-mapper-persistent-data 和 lvm2.



[zhouhh@mainServer ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

配置版本镜像库
  季度更新的稳定stable版和月度更新的edge版



[zhouhh@mainServer ~]$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
[zhouhh@mainServer ~]$ sudo yum-config-manager --enable docker-ce-edge

  这会在/etc/添加 /etc/yum.repos.d/docker-ce.repo 内容类似:



[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg

  由于docker.com服务器下载很慢,所以改为国内镜像.
  新建 /etc/yum.repos.d/docker.repo,内容为



[dockerrepo]
name=Docker Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker/yum/repo/centos7
enabled=1
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker/yum/gpg

  执行



[zhouhh@mainServer yum.repos.d]$ sudo yum makecache

  如需禁止edge版本, 可以执行下面的命令



[zhouhh@mainServer ~]$ sudo yum-config-manager --disable docker-ce-edge

安装docker



[zhouhh@mainServer ~]$ sudo yum makecache fast
[zhouhh@mainServer ~]$ sudo yum install docker-ce
Error: docker-ce conflicts with 2:docker-1.12.6-28.git1398f24.el7.centos.x86_64
Error: docker-ce-selinux conflicts with 2:container-selinux-2.12-2.gite7096ce.el7.noarch

  出现冲突, 原因是直接安装过docker.



[zhouhh@mainServer ~]$ yum list docker
Installed Packages
docker.x86_64                      2:1.12.6-28.git1398f24.el7.centos                      @extras
[zhouhh@mainServer ~]$ sudo yum erase docker.x86_64
Removed:
docker.x86_64 2:1.12.6-28.git1398f24.el7.centos
[zhouhh@mainServer ~]$ sudo yum list container-selinux-2.12-2.gite7096ce.el7.noarch
[zhouhh@mainServer ~]$ sudo yum erase container-selinux.noarch

  再安装:



[zhouhh@mainServer ~]$ sudo yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Installing:
docker-ce               x86_64       17.05.0.ce-1.el7.centos         docker-ce-edge        19 M
Installing for dependencies:
docker-ce-selinux       noarch       17.05.0.ce-1.el7.centos         docker-ce-edge        28 k
[Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/edge/Packages/docker-ce-17.05.0.ce-1.el7.centos.x86_64.rpm
Transaction check error:
file /usr/bin/docker from install of docker-ce-17.05.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-28.git1398f24.el7.centos.x86_64
file /usr/bin/docker-containerd from install of docker-ce-17.05.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-28.git1398f24.el7.centos.x86_64
file /usr/bin/docker-containerd-shim from install of docker-ce-17.05.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-28.git1398f24.el7.centos.x86_64
file /usr/bin/dockerd from install of docker-ce-17.05.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-28.git1398f24.el7.centos.x86_64
Error Summary


  如果生产系统需要稳定版本, 需要 yum list 进行查询. 但yum list只会显示二进制包, 加上.x86_64会显示包含源码包的全部的包. sort -r会按版本倒序排序.



[zhouhh@mainServer ~]$ yum list docker-ce.x86_64  --showduplicates |sort -r
* updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
* extras: mirror.bit.edu.cn
docker-ce.x86_64            17.05.0.ce-1.el7.centos             docker-ce-edge
docker-ce.x86_64            17.04.0.ce-1.el7.centos             docker-ce-edge
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
* base: mirror.bit.edu.cn

  第二列是版本号. el7表示centos7. 第三列是库名.
  安装指定版本: sudo yum install docker-ce-
  安装稳定版本:




[zhouhh@mainServer ~]$ sudo yum install docker-ce-17.03.1.ce-1.el7.centos
Installed:
docker-ce.x86_64 0:17.03.1.ce-1.el7.centos
Dependency Installed:
docker-ce-selinux.noarch 0:17.05.0.ce-1.el7.centos
Complete!


  # 删除老版本docker
  如果需要删除老的版本, 可以用如下的命令查询和删除. 老版本docker名字叫docker或docker-engine. 新版本社区版叫docker-ce, 企业版是docker-ee



[zhouhh@mainServer ~]$ yum list installed | grep docker
docker-client.x86_64                   2:1.12.6-28.git1398f24.el7.centos
docker-common.x86_64                   2:1.12.6-28.git1398f24.el7.centos
[zhouhh@mainServer ~]$ sudo yum erase -y docker-client.x86_64
[zhouhh@mainServer ~]$ sudo yum erase -y docker-common.x86_64
[zhouhh@mainServer ~]$ sudo yum remove docker \
docker-common \
container-selinux \
docker-selinux \
docker-engine

删除docker ce版和镜像



[zhouhh@mainServer ~]$ sudo yum remove docker-ce
[zhouhh@mainServer ~]$ sudo rm -rf /var/lib/docker

  可能还需要移除devicemapper, 重新格式化相关块设备.



[zhouhh@mainServer ~]$ sudo mkdir /etc/docker
[zhouhh@mainServer ~]$ sudo vi /etc/docker/daemon.json
{
"storage-driver": "devicemapper"
}

  对生产系统, 需要使用direct-lvm模式,需准备块设备,参考: devicemapper storage driver guide

启动测试docker
  Hello world的镜像启动后会打印”Hello from Docker!”然后退出.



[zhouhh@mainServer ~]$ sudo systemctl start docker
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.

非root用户启动docker



[zhouhh@mainServer ~]$ sudo groupadd docker
[zhouhh@mainServer ~]$ sudo usermod -aG docker $USER
[zhouhh@mainServer ~]$ exit
logout
[zhouhh@mainServer ~]$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

设置自启动
  大部分最新的linux发行版(RHEL, CentOS, Fedora, Ubuntu 16.04 以上), 都用sytemd来管理启动.



[zhouhh@mainServer ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

禁止自启动



[zhouhh@mainServer ~]$ sudo systemctl disable docker


参考
  Get Docker for CentOS

  如非注明转载, 均为原创. 本站遵循知识共享CC协议,转载请注明来源

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421521-1-1.html 上篇帖子: docker~学习笔记索引 下篇帖子: docker容器安装及使用技巧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表