CentOS下Docker 安装

一 安装Docker前提条件
目前,CentOS仅发行版本中的内核支持Docker。
Docker运行在CentOS 7上,要求系统为64位、系统内核版本为 3.10 以上。
 
二 查看CentOS环境信息
[root@localhost ~]# uname -r
3.10.0-327.36.3.el7.x86_64
[root@localhost ~]# 
 
三 安装Docker
Docker软件包和依赖包已经包含在默认的 CentOS-Extras软件源里,安装命令如下:
[root@localhost ~]# yum -y install docker
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                         | 3.6 kB  00:00:00     
extras                                                                                                       | 3.4 kB  00:00:00     
updates                                                                                                      | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                | 155 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                            | 139 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                                                           | 3.8 MB  00:00:07     
(4/4): base/7/x86_64/primary_db                                                                              | 5.6 MB  00:00:07     
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.12.6-11.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.12.6-11.el7.centos for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.12.6-11.el7.centos for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Processing Dependency: oci-systemd-hook >= 1:0.1.4-9 for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Processing Dependency: oci-register-machine >= 1:0-1.11 for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Processing Dependency: container-selinux >= 2:2.9-4 for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Processing Dependency: skopeo-containers for package: 2:docker-1.12.6-11.el7.centos.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.9-4.el7 will be installed
---> Package docker-client.x86_64 2:1.12.6-11.el7.centos will be installed
---> Package docker-common.x86_64 2:1.12.6-11.el7.centos will be installed
---> Package oci-register-machine.x86_64 1:0-1.11.gitdd0daef.el7 will be installed
---> Package oci-systemd-hook.x86_64 1:0.1.4-9.git671c428.el7 will be installed
---> Package skopeo-containers.x86_64 1:0.1.18-1.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
====================================================================================================================================
 Package                              Arch                   Version                                   Repository              Size
====================================================================================================================================
Installing:
 docker                               x86_64                 2:1.12.6-11.el7.centos                    extras                  20 M
Installing for dependencies:
 container-selinux                    noarch                 2:2.9-4.el7                               extras                  26 k
 docker-client                        x86_64                 2:1.12.6-11.el7.centos                    extras                 4.4 M
 docker-common                        x86_64                 2:1.12.6-11.el7.centos                    extras                  71 k
 oci-register-machine                 x86_64                 1:0-1.11.gitdd0daef.el7                   extras                 1.1 M
 oci-systemd-hook                     x86_64                 1:0.1.4-9.git671c428.el7                  extras                  29 k
 skopeo-containers                    x86_64                 1:0.1.18-1.el7                            extras                 7.6 k
 
Transaction Summary
====================================================================================================================================
Install  1 Package (+6 Dependent packages)
 
Total download size: 26 M
Installed size: 104 M
Downloading packages:
(1/7): container-selinux-2.9-4.el7.noarch.rpm                                                                |  26 kB  00:00:01     
(2/7): oci-systemd-hook-0.1.4-9.git671c428.el7.x86_64.rpm                                                    |  29 kB  00:00:00     
(3/7): skopeo-containers-0.1.18-1.el7.x86_64.rpm                                                             | 7.6 kB  00:00:00     
(4/7): docker-client-1.12.6-11.el7.centos.x86_64.rpm                                                         | 4.4 MB  00:00:03     
(5/7): docker-1.12.6-11.el7.centos.x86_64.rpm                                                                |  20 MB  00:00:06     
(6/7): docker-common-1.12.6-11.el7.centos.x86_64.rpm                                                         |  71 kB  00:00:07     
(7/7): oci-register-machine-0-1.11.gitdd0daef.el7.x86_64.rpm                                                 | 1.1 MB  00:00:08     
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               3.1 MB/s |  26 MB  00:00:08     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:docker-common-1.12.6-11.el7.centos.x86_64                                                                      1/7 
  Installing : 2:docker-client-1.12.6-11.el7.centos.x86_64                                                                      2/7 
  Installing : 1:oci-systemd-hook-0.1.4-9.git671c428.el7.x86_64                                                                 3/7 
  Installing : 1:oci-register-machine-0-1.11.gitdd0daef.el7.x86_64                                                              4/7 
  Installing : 1:skopeo-containers-0.1.18-1.el7.x86_64                                                                          5/7 
  Installing : 2:container-selinux-2.9-4.el7.noarch                                                                             6/7 
setsebool:  SELinux is disabled.
/usr/sbin/semodule: invalid option -- 'X'
  Installing : 2:docker-1.12.6-11.el7.centos.x86_64                                                                             7/7 
  Verifying  : 2:container-selinux-2.9-4.el7.noarch                                                                             1/7 
  Verifying  : 2:docker-1.12.6-11.el7.centos.x86_64                                                                             2/7 
  Verifying  : 1:skopeo-containers-0.1.18-1.el7.x86_64                                                                          3/7 
  Verifying  : 1:oci-register-machine-0-1.11.gitdd0daef.el7.x86_64                                                              4/7 
  Verifying  : 2:docker-common-1.12.6-11.el7.centos.x86_64                                                                      5/7 
  Verifying  : 2:docker-client-1.12.6-11.el7.centos.x86_64                                                                      6/7 
  Verifying  : 1:oci-systemd-hook-0.1.4-9.git671c428.el7.x86_64                                                                 7/7 
 
Installed:
  docker.x86_64 2:1.12.6-11.el7.centos                                                                                              
 
Dependency Installed:
  container-selinux.noarch 2:2.9-4.el7                            docker-client.x86_64 2:1.12.6-11.el7.centos                       
  docker-common.x86_64 2:1.12.6-11.el7.centos                     oci-register-machine.x86_64 1:0-1.11.gitdd0daef.el7               
  oci-systemd-hook.x86_64 1:0.1.4-9.git671c428.el7                skopeo-containers.x86_64 1:0.1.18-1.el7                           
 
Complete!
 
四 启动Docker后台服务
[root@localhost ~]# service docker start
 
五 测试运行 hello-world
由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
 
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.
 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://cloud.docker.com/
 
For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

猜你喜欢

转载自cakin24.iteye.com/blog/2371754