CentOS Docker 安装

Docker支持以下的CentOS版本:

CentOS 7 (64-bit)
CentOS 6.5 (64-bit) 或更高的版本

版本要求

目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

查看操作系统版本

[root@Optimus ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

[root@Optimus ~]# cat /proc/version
Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014

安装

教程参考:

Docker的安装配置及使用详解

Centos docker安装

安装docker

1. yum install -y epel-releas
2. yum install docker-io

clipboard.png

[root@Optimus ~]# yum install docker-io
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink                                                                                                                                                                                             | 7.1 kB     00:00     
 * base: mirrors.btte.net
 * epel: ftp.riken.jp
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
base                                                                                                                                                                                                      | 3.7 kB     00:00     
epel                                                                                                                                                                                                      | 4.3 kB     00:00     
epel/primary_db                                                                                                                                                                                           | 5.9 MB     00:40     
extras                                                                                                                                                                                                    | 3.4 kB     00:00     
nginx                                                                                                                                                                                                     | 2.9 kB     00:00     
updates                                                                                                                                                                                                   | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                                        | 4.7 MB     00:26     
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:1.7.1-2.el6 will be installed
--> Processing Dependency: lxc for package: docker-io-1.7.1-2.el6.x86_64
--> Processing Dependency: libcgroup for package: docker-io-1.7.1-2.el6.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 0:0.40.rc1-24.el6_9 will be installed
---> Package lxc.x86_64 0:1.0.10-2.el6 will be installed
--> Processing Dependency: lua-lxc(x86-64) = 1.0.10-2.el6 for package: lxc-1.0.10-2.el6.x86_64
--> Processing Dependency: lua-alt-getopt for package: lxc-1.0.10-2.el6.x86_64
--> Processing Dependency: liblxc.so.1()(64bit) for package: lxc-1.0.10-2.el6.x86_64
--> Running transaction check
---> Package lua-alt-getopt.noarch 0:0.7.0-1.el6 will be installed
---> Package lua-lxc.x86_64 0:1.0.10-2.el6 will be installed
--> Processing Dependency: lua-filesystem for package: lua-lxc-1.0.10-2.el6.x86_64
---> Package lxc-libs.x86_64 0:1.0.10-2.el6 will be installed
--> Running transaction check
---> Package lua-filesystem.x86_64 0:1.4.2-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================================
 Package                                                  Arch                                             Version                                                       Repository                                         Size
=================================================================================================================================================================================================================================
Installing:
 docker-io                                                x86_64                                           1.7.1-2.el6                                                   epel                                              4.6 M
Installing for dependencies:
 libcgroup                                                x86_64                                           0.40.rc1-24.el6_9                                             updates                                           131 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.10-2.el6                                                  epel                                               16 k
 lxc                                                      x86_64                                           1.0.10-2.el6                                                  epel                                              124 k
 lxc-libs                                                 x86_64                                           1.0.10-2.el6                                                  epel                                              258 k

Transaction Summary
=================================================================================================================================================================================================================================
Install       7 Package(s)

Total download size: 5.1 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): docker-io-1.7.1-2.el6.x86_64.rpm                                                                                                                                                                   | 4.6 MB     00:25     
(2/7): libcgroup-0.40.rc1-24.el6_9.x86_64.rpm                                                                                                                                                             | 131 kB     00:00     
(3/7): lua-alt-getopt-0.7.0-1.el6.noarch.rpm                                                                                                                                                              | 6.9 kB     00:00     
(4/7): lua-filesystem-1.4.2-1.el6.x86_64.rpm                                                                                                                                                              |  24 kB     00:00     
(5/7): lua-lxc-1.0.10-2.el6.x86_64.rpm                                                                                                                                                                    |  16 kB     00:00     
(6/7): lxc-1.0.10-2.el6.x86_64.rpm                                                                                                                                                                        | 124 kB     00:00     
(7/7): lxc-libs-1.0.10-2.el6.x86_64.rpm                                                                                                                                                                   | 258 kB     00:01     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                            177 kB/s | 5.1 MB     00:29     
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 (@extras)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lxc-libs-1.0.10-2.el6.x86_64                                                                                                                                                                                  1/7 
  Installing : lua-filesystem-1.4.2-1.el6.x86_64                                                                                                                                                                             2/7 
  Installing : lua-lxc-1.0.10-2.el6.x86_64                                                                                                                                                                                   3/7 
  Installing : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                                                                                                             4/7 
  Installing : lxc-1.0.10-2.el6.x86_64                                                                                                                                                                                       5/7 
  Installing : libcgroup-0.40.rc1-24.el6_9.x86_64                                                                                                                                                                            6/7 
  Installing : docker-io-1.7.1-2.el6.x86_64                                                                                                                                                                                  7/7 
  Verifying  : lua-lxc-1.0.10-2.el6.x86_64                                                                                                                                                                                   1/7 
  Verifying  : lxc-libs-1.0.10-2.el6.x86_64                                                                                                                                                                                  2/7 
  Verifying  : libcgroup-0.40.rc1-24.el6_9.x86_64                                                                                                                                                                            3/7 
  Verifying  : lxc-1.0.10-2.el6.x86_64                                                                                                                                                                                       4/7 
  Verifying  : docker-io-1.7.1-2.el6.x86_64                                                                                                                                                                                  5/7 
  Verifying  : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                                                                                                             6/7 
  Verifying  : lua-filesystem-1.4.2-1.el6.x86_64                                                                                                                                                                             7/7 

Installed:
  docker-io.x86_64 0:1.7.1-2.el6                                                                                                                                                                                                 

Dependency Installed:
  libcgroup.x86_64 0:0.40.rc1-24.el6_9     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.10-2.el6     lxc.x86_64 0:1.0.10-2.el6     lxc-libs.x86_64 0:1.0.10-2.el6    

Complete!

加入开机启动

[root@Optimus ~]# chkconfig docker on

启动docker

[root@Optimus ~]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:                                       [  OK  ]

查看docker版本

[root@Optimus ~]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64

查看docker信息

[root@Optimus ~]# docker info
Containers: 0
Images: 0
Storage Driver: devicemapper
 Pool Name: docker-8:1-67240264-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 305.7 MB
 Data Space Total: 107.4 GB
 Data Space Available: 107.1 GB
 Metadata Space Used: 733.2 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.89-RHEL6 (2014-09-01)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-504.el6.x86_64
Operating System: <unknown>
CPUs: 24
Total Memory: 15.52 GiB
Name: Optimus
ID: OKJW:54WI:244F:NBPA:ULP6:LTA3:TJ5T:4VNH:EALS:YGYJ:POLS:WIV5

下载centos镜像

[root@Optimus ~]# docker pull centos
latest: Pulling from centos
6c5159923047: Pull complete 
acec82331181: Pull complete 
1c1b67b33c28: Pull complete 
Digest: sha256:57c91a43765de2147fa666a128477bc6101d6fda660feaaa5fbb1a8b110c934f
Status: Downloaded newer image for centos:latest

查看镜像

[root@Optimus ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              1c1b67b33c28        5 weeks ago         196.6 MB

运行centos镜像

[root@Optimus ~]# docker run -i -t centos /bin/bash
[root@0d1f6225836b /]# 

查找镜像

[root@Optimus ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              1c1b67b33c28        5 weeks ago         196.6 MB
[root@Optimus ~]# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              1c1b67b33c28        5 weeks ago         196.6 MB
<none>              <none>              6c5159923047        5 weeks ago         196.6 MB
<none>              <none>              acec82331181        5 weeks ago         196.6 MB

删除镜像:第一次删除时显示冲突,加-f强制删除

[root@Optimus ~]# docker rmi 1c1b67b33c28
Error response from daemon: Conflict, cannot delete 1c1b67b33c28 because the container 0d1f6225836b is using it, use -f to force
Error: failed to remove images: [1c1b67b33c28]
[root@Optimus ~]# docker rmi -f 1c1b67b33c28 
Untagged: centos:latest
Deleted: 1c1b67b33c2810dcdbe70cf5ab186f1de50b138d06877e6b8421d5329a70beb1
Deleted: acec82331181312afa99df6a79e541ea819d64d32af6f4d3656897ce63d55f88
Deleted: 6c51599230478bde53cfcf5f4e7f68c2bf295102f31146c0bb6e9b814365c0e7
[root@Optimus ~]# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
[root@Optimus ~]# 

afra
225 声望23 粉丝

你的努力程度之低 远还没有到比拼天赋的需要。