CentOS6.5安装Docker 阿里云服务器centos6.5 安装docker报错的问题解决方案



笔者这里是用CnetOS6.5系统,开始安装Docker之旅:
 
[root@localhost ~]# uname -r
2.6.32-431.el6.x86_64
 
[root@localhost ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

注意其他的源可能导致你的内核和docker的版本不一致,需要升级内核至3.x。
 
安装:

[root@localhost ~]# rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.JN76fI: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
  1:epel-release          ########################################### [100%]
[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[root@localhost ~]# yum -y install docker-io

启动并设置开机自动启动

[root@localhost ~]# service docker start
Starting cgconfig service:                                [确定]
Starting docker:                                      [确定]
[root@localhost ~]# chkconfig docker on

获取cnetos镜像

[root@localhost ~]# docker pull centos:latest
centos:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete 
5b12ef8fd570: Pull complete 
34943839435d: Downloading [===>                                              ] 18.38 MB/232.5 MB 1h7m49s
 

#官方安装方式docker pull imagename从docker的索引中心下载,imagename是镜像名称,例如docker pull Ubuntu就是下载base ubuntu并且tag是latest。

我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

扫描二维码关注公众号,回复: 4162993 查看本文章

查看docker镜像
 
[root@localhost ~]# docker images centos
REPOSITORY          TAG                IMAGE ID            CREATED                  VIRTUAL SIZE
centos              latest              34943839435d        Less than a second ago  224 MB

运行docker运行shell
 
[root@localhost ~]# docker run -i -t centos /bin/bash
[root@2ce733141ece /]# 
[root@2ce733141ece /]# 
[root@2ce733141ece /]# 
[root@2ce733141ece /]#

停止容器

[root@localhost ~]# docker stop <CONTAINER ID>

删除所有容器

docker rm $(docker ps -a -q)

查看docker的子命令,直接敲docker 或完整的docker help 就可以 
 
常用命令

总结一下常用命令:

其中<>阔起来的参数为必选,[]阔起来为可选 

  • docker version 查看docker的版本号,包括客户端、服务端、依赖的Go等
  • docker info 查看系统(docker)层面信息,包括管理的images, containers数等
  • docker search  在docker index中搜索image
  • docker pull  从docker registry server 中下拉image
  • docker push  推送一个image或repository到registry
  • docker push :TAG 同上,指定tag
  • docker inspect  查看image或container的底层信息
  • docker images TODO filter out the intermediate image layers (intermediate image layers 是什么)
  • docker images -a 列出所有的images
  • docker ps 默认显示正在运行中的container
  • docker ps -l 显示最后一次创建的container,包括未运行的
  • docker ps -a 显示所有的container,包括未运行的
  • docker logs  查看container的日志,也就是执行命令的一些输出
  • docker rm  删除一个或多个container
  • docker rm `docker ps -a -q` 删除所有的container
  • docker ps -a -q | xargs docker rm 同上, 删除所有的container
  • docker rmi  删除一个或多个image
  • docker start/stop/restart  开启/停止/重启container
  • docker start -i  启动一个container并进入交互模式
  • docker attach  attach一个运行中的container
  • docker run  使用image创建container并执行相应命令,然后停止
  • docker run -i -t  /bin/bash 使用image创建container并进入交互模式, login shell是/bin/bash
  • docker run -i -t -p  将container的端口映射到宿主机的端口
  • docker commit  [repo:tag] 将一个container固化为一个新的image,后面的repo:tag可选
  • docker build
  •  寻找path路径下名为的Dockerfile的配置文件,使用此配置生成新的image
  • docker build -t repo[:tag] 同上,可以指定repo和可选的tag
  • docker build -  使用指定的dockerfile配置文件,docker以stdin方式获取内容,使用此配置生成新的image
  • docker port  查看本地哪个端口映射到container的指定端口,其实用docker ps 也可以看到

CentOS 6/7系列安装Docker http://www.linuxidc.com/Linux/2014-07/104768.htm

Docker的搭建Gitlab CI 全过程详解 http://www.linuxidc.com/Linux/2013-12/93537.htm

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm

在 Docker 中使用 MySQL http://www.linuxidc.com/Linux/2014-01/95354.htm

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm

Ubuntu 14.04安装Docker  http://www.linuxidc.com/linux/2014-08/105656.htm

阿里云CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm

Docker 的详细介绍请点这里
Docker 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2015-01/111091.htm
 




阿里云服务器centos6.5 安装docker报错的问题解决方案

首先确认你的linux内核版本

# lsb_release -a
  • 1

LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch 
Distributor ID: CentOS 
Description: CentOS release 6.5 (Final) 
Release: 6.5 
Codename: Final

# uname -a
  • 1

Linux xxxxxxx 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

因为 Docker 推荐使用 3.8 以上内核,所以我们选择使用 YUM 方式来升级内核

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
  • 1
  • 2
  • 3
# vi /etc/grub.conf 
  • 1

修改默认的启动内核,新安装的内核一般在第一个,这里把default = 1 改为 default = 0 就好了

reboot重启主机检查内核是否升级

升级内核后还是报错

报错信息

#docker info
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
  • 1
  • 2
# docker -d
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 
docker: relocation error: docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
  • 1
  • 2
  • 3

根据CentOS 6.5上尝试docker遇到的几个问题

应该是libmapper有关,需要升级下这个库:

 #yum-config-manager --enable public_ol6_latest
 #yum install device-mapper-event-libs

首先确认你的linux内核版本

# lsb_release -a
  • 1

LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch 
Distributor ID: CentOS 
Description: CentOS release 6.5 (Final) 
Release: 6.5 
Codename: Final

# uname -a
  • 1

Linux xxxxxxx 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

因为 Docker 推荐使用 3.8 以上内核,所以我们选择使用 YUM 方式来升级内核

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
  • 1
  • 2
  • 3
# vi /etc/grub.conf 
  • 1

修改默认的启动内核,新安装的内核一般在第一个,这里把default = 1 改为 default = 0 就好了

reboot重启主机检查内核是否升级

升级内核后还是报错

报错信息

#docker info
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
  • 1
  • 2
# docker -d
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 
docker: relocation error: docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
  • 1
  • 2
  • 3

根据CentOS 6.5上尝试docker遇到的几个问题

应该是libmapper有关,需要升级下这个库:

 #yum-config-manager --enable public_ol6_latest
 #yum install device-mapper-event-libs

猜你喜欢

转载自blog.csdn.net/weixin_36385007/article/details/80733829