CentOS 6.5 安装 Docker

- 开始安装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

- 获取centos镜像:

[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

- 查看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@localhost ~]# docker stop <CONTAINER ID>