二、Docker 安装运行

2.1 Docker安装

1、Docker使用EPEL发布,RHEL系的OS首先要确保已经持有EPEL仓库,否则先检查OS的版本,然后安装相应的EPEL包;如下命令:

[root@boxiaoyuan ~]# yum install -y epel-release

2、正式安装Docker,执行如下命令:

[root@boxiaoyuan ~]# yum install -y docker-io

说明:有时候上面这种方式无法安装,可以使用如下命令进行安装:

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

3、在/etc/sysconfig 目录下发现有安装后的配置文件:docker文件,说明Docker安装成功:

4、启动Docker后台服务,执行如下命令:

[root@boxiaoyuan sysconfig]# service docker start
Starting docker: [确定]

5、查看Docker版本,出现以下内容,说明Docker安装成功,命令如下:获取当前 docker 版本

[root@boxiaoyuan sysconfig]# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
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
OS/Arch (server): linux/amd64

2.2 Docker配置阿里云镜像加速器

1、打开网站https://dev.aliyun.com,登录阿里云账号(没有的可以注册,也可以用淘宝等第三方账号登录):

 

2、点击镜像加速器,复制加速器地址:

 

3、配置本机Docker运行镜像加速器,打开/etc/sysconfig/docker文件,粘贴配置阿里加速器地址,配置如下:

 

4、重启Docker,使用service docker restart命令:

[root@boxiaoyuan sysconfig]# vim docker
[root@boxiaoyuan sysconfig]# service docker restart
停止 docker:                                              [确定]
Starting docker:                                           [确定]

5、使用ps -ef|grep docker查看docker进程,出现如下信息,说明配置成功:

[root@boxiaoyuan sysconfig]# ps -ef | grep docker 
root      53122      1  0 00:52 pts/1    00:00:00 /usr/bin/docker -d --registry-mirror=https://eh7x0g3c.mirror.aliyuncs.com
root      53174  38348  0 00:53 pts/1    00:00:00 grep docker 

2.3 测试运行Hello-world

1、使用docker run hello-world命令运行测试hello-world镜像,如下:

[root@boxiaoyuan sysconfig]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
65b27d3bd74d: Pull complete 
9f5834b25059: Pull complete 
Digest: sha256:fb158b7ad66f4d58aa66c4455858230cd2eab4cdf29b13e5c3628a6bfc2e9f05
Status: Downloaded newer image for hello-world:latest

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/

注:由于本地没有hello-world这镜像,所以会下载一个helloworld的镜像,并在容器内运行。

2、run 命令都干了什么?如下图:

 

3、为什么Docker比vm快?

 

猜你喜欢

转载自www.cnblogs.com/zhuzhaoli/p/11141105.html