CentOS6.5下安装Docker(一)

本文详细介绍如何在CentOS 6.5上升级内核至4.4.170以改善Docker运行效率,并提供了详细的Docker安装、配置及测试步骤。针对常见问题如DNS配置、SSL连接错误等也给出了具体解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一、简介

 CentOS 6.5 的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到更高版本,本次教程升级版本为4.4.170-1.el6.elrepo.x86_64。

二、升级内核

1、查看内核版本命令

uname -r

2、导入key(需要root权限):rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

问题1:如果报错 curl: (6) Couldn't resolve host 'www.elrepo.org' 则表示DNS解析有问题,需要配置

vi /etc/sysconfig/network-scripts/ifcfg-eth0

末尾添加DNS配置,如下图: 

 查看nameserver是否显示正确 

重新导入key。

问题2:如果报curl: (35) SSL connect error错误则输入

 yum update nss

如果没有nss,则需要安装nss服务

yum install nss

3、安装ELRepo到CentOS

rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

4、安装内核

yum --enablerepo=elrepo-kernel install kernel-lt –y

5、修改引导文件,将默认引导改为0

 vi /etc/grub.conf  # 改为default=0
6、重启查看版本
reboot

重启完成后查看内核版本:

# uname -r
4.4.170-1.el6.elrepo.x86_64

 三、安装docker

1、安装docker

yum install docker-io

如果提示错误:No package docker-io available,则运行

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

(上一个步骤试了无效)直接用下载源安装,执行命令:yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm 

然后再次执行上面的安装命令。

2、启动dacker

service docker start

3、查看docker版本

# docker version
Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): linux/amd64
Server version: 1.7.0
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 0baf609
OS/Arch (server): linux/amd64

问题:这里可能会报一个错误

// 启动以后提示
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
 
// 或者查看status时提示以下内容
# docker status
docker 已死,但 pid 文件仍存
 
//查看日志提示如下
# tail -f /var/log/docker
time="2015-03-09T16:05:29+08:00" level="info" msg="+job serveapi(unix:///var/run/docker.sock)"
time="2015-03-09T16:05:29+08:00" level="info" msg="WARNING: You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.8.0."
time="2015-03-09T16:05:29+08:00" level="info" msg="Listening for HTTP on unix (/var/run/docker.sock)"
/usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

那么运行以下内容:

# yum install device-mapper-event-libs
// 然后重启docker
# docker restart

4、运行hello-world

完成后测试hello-world出现问题(Unable to find image 'hello-world:latest' locally)

dockerè¿è¡hello-worldéå

docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取镜像,出项这个问题的原因:是应为docker服务器再国外,我们在国内
无法正常拉取镜像,所以就需要我们为docker设置国内阿里云的镜像加速器;
需要修改配置文件      /etc/docker/daemon.json  如下

{ 
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"] 
}

然后重启 

# docker run hello-world
 
Hello 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 the
    executable that produces the output you are currently reading.
 4. 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/get-started/

这样docker就算安装成功了。

四、卸载Docker

查看已安装的包:

yum list installed | grep docker

删除软件包:

yum -y remove docker-io.x86_64

删除镜像/容器:

rm -rf /var/lib/docker

参考文档:CentOS6.5下安装Docker

参考二

docker 安装完成后测试hello-world出现问题(Unable to find image 'hello-world:latest' locally)

拓展阅读(docker-io, docker-ce, docker-ee 区别)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值