Centos 6.X安装docker

Docker是什么就不多说了,见docker基础原理介绍。
docker容器最早受到RHEL完善的支持是从最近的CentOS 7.0开始的,官方说明是只能运行于64位架构平台,内核版本为2.6.32-431及以上(即>=CentOS 6.5,运行docker时实际提示3.8.0及以上),升级内核请参考CentOS 6.x 内核升级(2.6.32 -> 3.10.58)过程记录
需要注意的是CentOS 6.5与7.0的安装是有一点点不同的,CentOS-6上docker的安装包叫docker-io,并且来源于Fedora epel库,这个仓库维护了大量的没有包含在发行版中的软件,所以先要安装EPEL,而CentOS-7的docker直接包含在官方镜像源的Extras仓库(CentOS-Base.repo下的[extras]节enable=1启用)。前提是都需要联网,具体安装过程如下。

1、查看系统版本和内核
[root@xinglinglove ~]# cat /etc/centos-release
CentOS release 6.6 (Final)
[root@xinglinglove ~]# uname -a
Linux xinglinglove 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
2、查询selinux的状态
[root@xinglinglove ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
3、 禁用selinux
[root@xinglinglove ~]# vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

3、修改SELINUX=disabled,保存并退出
[root@xinglinglove ~]# getenforce
Enforcing
[root@xinglinglove ~]# setenforce 0
4、安装 Fedora EPEL
[root@xinglinglove ~]# wget http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
–2017-05-21 22:33:32– http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
正在解析主机 ftp.riken.jp… 134.160.38.1
正在连接 ftp.riken.jp|134.160.38.1|:80… 已连接。
已发出 HTTP 请求,正在等待回应… 200 OK
长度:14540 (14K) [text/plain]
正在保存至: “epel-release-6-8.noarch.rpm”

100%[====================================================================================================================================================================================================================================>] 14,540 –.-K/s in 0.1s

2017-05-21 22:33:33 (107 KB/s) - 已保存 “epel-release-6-8.noarch.rpm” [14540/14540])

[root@xinglinglove ~]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing… ########################################### [100%]
1:epel-release ########################################### [100%]

[root@xinglinglove ~]# yum install lxc libcgrouop
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
epel/metalink | 5.7 kB 00:00
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.btte.net
* updates: mirrors.btte.net
epel | 4.3 kB 00:00
epel/primary_db | 5.9 MB 00:07
No package libcgrouop available.
解决依赖关系
–> 执行事务检查
—> Package lxc.x86_64 0:1.0.9-1.el6 will be 安装
–> 处理依赖关系 lua-lxc(x86-64) = 1.0.9-1.el6,它被软件包 lxc-1.0.9-1.el6.x86_64 需要
–> 处理依赖关系 lua-alt-getopt,它被软件包 lxc-1.0.9-1.el6.x86_64 需要
–> 处理依赖关系 liblxc.so.1()(64bit),它被软件包 lxc-1.0.9-1.el6.x86_64 需要
–> 执行事务检查
—> Package lua-alt-getopt.noarch 0:0.7.0-1.el6 will be 安装
—> Package lua-lxc.x86_64 0:1.0.9-1.el6 will be 安装
–> 处理依赖关系 lua-filesystem,它被软件包 lua-lxc-1.0.9-1.el6.x86_64 需要
—> Package lxc-libs.x86_64 0:1.0.9-1.el6 will be 安装
–> 执行事务检查
—> Package lua-filesystem.x86_64 0:1.4.2-1.el6 will be 安装
–> 完成依赖关系计算

依赖关系解决

==============================================================================================================================================================================================================================================================================

软件包 架构 版本 仓库 大小

正在安装:
lxc x86_64 1.0.9-1.el6 epel 122 k
为依赖而安装:
lua-alt-getopt noarch 0.7.0-1.el6 epel 6.9 k
lua-filesystem x86_64 1.4.2-1.el6 epel 24 k
lua-lxc x86_64 1.0.9-1.el6 epel 16 k
lxc-libs x86_64 1.0.9-1.el6 epel 257 k

事务概要

Install 5 Package(s)

总下载量:427 k
Installed size: 951 k
确定吗?[y/N]:y
下载软件包:
(1/5): lua-alt-getopt-0.7.0-1.el6.noarch.rpm | 6.9 kB 00:00
(2/5): lua-filesystem-1.4.2-1.el6.x86_64.rpm | 24 kB 00:00
(3/5): lua-lxc-1.0.9-1.el6.x86_64.rpm | 16 kB 00:00
(4/5): lxc-1.0.9-1.el6.x86_64.rpm | 122 kB 00:00

(5/5): lxc-libs-1.0.9-1.el6.x86_64.rpm | 257 kB 00:00

总计 687 kB/s | 427 kB 00:00
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : EPEL (6) epel@fedoraproject.org
Package: epel-release-6-8.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
确定吗?[y/N]:y
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
正在安装 : lxc-libs-1.0.9-1.el6.x86_64 1/5
正在安装 : lua-filesystem-1.4.2-1.el6.x86_64 2/5
正在安装 : lua-lxc-1.0.9-1.el6.x86_64 3/5
正在安装 : lua-alt-getopt-0.7.0-1.el6.noarch 4/5
正在安装 : lxc-1.0.9-1.el6.x86_64 5/5
Verifying : lua-alt-getopt-0.7.0-1.el6.noarch 1/5
Verifying : lxc-1.0.9-1.el6.x86_64 2/5
Verifying : lua-filesystem-1.4.2-1.el6.x86_64 3/5
Verifying : lua-lxc-1.0.9-1.el6.x86_64 4/5
Verifying : lxc-libs-1.0.9-1.el6.x86_64 5/5
已安装:
lxc.x86_64 0:1.0.9-1.el6
作为依赖被安装:
lua-alt-getopt.noarch 0:0.7.0-1.el6 lua-filesystem.x86_64 0:1.4.2-1.el6 lua-lxc.x86_64 0:1.0.9-1.el6 lxc-libs.x86_64 0:1.0.9-1.el6
完毕!
5、安装docker
[root@xinglinglove ~]# yum install docker-io
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.btte.net
* updates: mirrors.btte.net
解决依赖关系
–> 执行事务检查
—> Package docker-io.x86_64 0:1.7.1-2.el6 will be 安装
–> 完成依赖关系计算

依赖关系解决

==============================================================================================================================================================================================================================================================================

软件包 架构 版本 仓库 大小

正在安装:
docker-io x86_64 1.7.1-2.el6 epel 4.6 M

事务概要

Install 1 Package(s)
总下载量:4.6 M
Installed size: 19 M
确定吗?[y/N]:y
下载软件包:
docker-io-1.7.1-2.el6.x86_64.rpm | 4.6 MB 00:01
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : docker-io-1.7.1-2.el6.x86_64 1/1
Verifying : docker-io-1.7.1-2.el6.x86_64 1/1
已安装:
docker-io.x86_64 0:1.7.1-2.el6
完毕!
6、启动docker
[root@xinglinglove ~]# /etc/init.d/docker start
Starting cgconfig service: [确定]
Starting docker: [确定]
[root@xinglinglove ~]# ps -ef|grep docker
root 3381 1 2 22:39 pts/1 00:00:00 /usr/bin/docker -d
root 3503 3134 0 22:39 pts/1 00:00:00 grep docker
7、测试并拉取镜像
[root@xinglinglove ~]# docker pull centos
latest: Pulling from centos
5932f74ff0cd: Pull complete
4a7b890637c2: Pull complete
4beff0251382: Pull complete
Digest: sha256:cb2a2bffb199880da9c69e7f647c01c720c6f95b186a86cfbd3ef168b8032074
Status: Downloaded newer image for centos:latest
[root@xinglinglove ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest 4beff0251382 9 days ago 192.5 MB
8、创建容器
[root@xinglinglove ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest 4beff0251382 9 days ago 192.5 MB
[root@xinglinglove ~]# docker run -itd centos /bin/bash
a7c7d5bb70b0b04aae9e47d6f05be352facc8b5270b04d0ac752510bdcd8a8c1
[root@xinglinglove ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7c7d5bb70b0 centos “/bin/bash” 15 seconds ago Up 14 seconds sleepy_euclid
[root@xinglinglove ~]# docker exec -it a7c7d5bb70b0 /bin/bash
[root@a7c7d5bb70b0 /]#
9、导出容器镜像
[root@xinglinglove ~]# docker export a7c7d5bb70b0 > centos7.tar
[root@xinglinglove ~]# ll centos7.tar
-rw-r–r–. 1 root root 200184832 5月 21 22:55 centos7.tar
10、将镜像远程拷贝到另一台机器上测试镜像是否可以用
[root@xinglinglove ~]# scp centos7.tar root@192.168.31.182:/
The authenticity of host ‘192.168.31.182 (192.168.31.182)’ can’t be established.
RSA key fingerprint is ee:20:cc:fc:bd:f3:43:9f:67:95:83:67:d9:1c:fa:9f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.31.182’ (RSA) to the list of known hosts.
root@192.168.31.182’s password:
centos7.tar 100% 191MB 31.8MB/s 00:06
用xshell 连到192.168.31.182这台服务器上
[root@xinglinglove /]# ls
bin boot centos7.tar data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@xinglinglove /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@xinglinglove /]# cat centos7.tar | docker import - centos7-v1
sha256:c74ccf891cd7ca7528e605c2e1e7e7bb3427b5d528c3ade78e18a04d9a231569
[root@xinglinglove /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7-v1 latest c74ccf891cd7 18 seconds ago 193MB
[root@xinglinglove /]# docker run -it –name mycentos centos7-v1 /bin/bash
[root@244e4b1845b0 /]# exit
[root@xinglinglove /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
244e4b1845b0 centos7-v1 “/bin/bash” 4 minutes ago Exited (127) 2 minutes ago mycentos

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值