Dcoker2-安装

1. 安装要求

  • CentOS 7 (64-bit) 以上: 要求系统为64位、系统内核版本为 3.10 以上。
  • CentOS-6.5或更高的: 要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
[root@bogon Desktop]$ uname -r
2.6.32-642.3.1.el6.x86_64
[root@bogon Desktop]$ cat /etc/redhat-release 
CentOS release 6.8 (Final)

2.安装操作

官方安装手册 https://docs.docker.com/install/linux/docker-ce/centos/
中文安装手册 https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/#prerequisites

2.1 安装EPEL

Docker使用EPEL发布,RHEL系的OS首先要确保已经持有EPEL仓库,否则先检查OS的版本,然后安装相应的EPEL包。

yum install -y epel-release



[root@bogon Desktop]# yum install -y epel-release
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Determining fastest mirrors
 * base: mirror.lzu.edu.cn
 * extras: mirror.lzu.edu.cn
 * updates: mirrors.aliyun.com
base                                                                                                                                  | 3.7 kB     00:00     
base/primary_db                                                                                                                       | 4.7 MB     00:03     
extras                                                                                                                                | 3.4 kB     00:00     
extras/primary_db                                                                                                                     |  29 kB     00:00     
updates                                                                                                                               | 3.4 kB     00:00     
updates/primary_db                                                                                                                    | 8.9 MB     00:02     
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:6-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                   Arch                                Version                             Repository                           Size
=============================================================================================================================================================
Installing:
 epel-release                              noarch                              6-8                                 extras                               14 k

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

Total download size: 14 k
Installed size: 22 k
Downloading Packages:
epel-release-6-8.noarch.rpm                                                                                                           |  14 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : epel-release-6-8.noarch                                                                                                                   1/1 
  Verifying  : epel-release-6-8.noarch                                                                                                                   1/1 

Installed:
  epel-release.noarch 0:6-8                                                                                                                                  

Complete!
[root@bogon Desktop]# 

2.2 安装docker

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

[root@bogon Desktop]# 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
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
docker-engine-1.7.1-1.el6.x86_64.rpm                                                                                                  | 4.5 MB     00:37     
Examining /var/tmp/yum-root-6ceB1q/docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
Marking /var/tmp/yum-root-6ceB1q/docker-engine-1.7.1-1.el6.x86_64.rpm to be installed
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * epel: ftp.iij.ad.jp
 * extras: mirror.lzu.edu.cn
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be installed
--> Processing Dependency: libcgroup for package: docker-engine-1.7.1-1.el6.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 0:0.40.rc1-27.el6_10 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                          Arch                      Version                               Repository                                            Size
=============================================================================================================================================================
Installing:
 docker-engine                    x86_64                    1.7.1-1.el6                           /docker-engine-1.7.1-1.el6.x86_64                     19 M
Installing for dependencies:
 libcgroup                        x86_64                    0.40.rc1-27.el6_10                    updates                                              131 k

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

Total size: 19 M
Total download size: 131 k
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
libcgroup-0.40.rc1-27.el6_10.x86_64.rpm                                                                                               | 131 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libcgroup-0.40.rc1-27.el6_10.x86_64                                                                                                       1/2 
  Installing : docker-engine-1.7.1-1.el6.x86_64                                                                                                          2/2 
  Verifying  : docker-engine-1.7.1-1.el6.x86_64                                                                                                          1/2 
  Verifying  : libcgroup-0.40.rc1-27.el6_10.x86_64                                                                                                       2/2 

Installed:
  docker-engine.x86_64 0:1.7.1-1.el6                                                                                                                         

Dependency Installed:
  libcgroup.x86_64 0:0.40.rc1-27.el6_10                                                                                                                      

Complete!

2.3 查看安装结果并启动


[root@bogon Desktop]# 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
Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
[root@bogon Desktop]# 

[root@bogon sysconfig]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:	                                   [  OK  ]
[root@bogon sysconfig]# 

2.4 配置文件

[root@bogon sysconfig]# cat /etc/sysconfig/docker 
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

other_args=""
[root@bogon sysconfig]# 

2.5 CentOS 7下安装

Install Docker Engine on CentOS

## 查看版本号 
cat /etc/redhat-release

## yum安装gcc相关
yum -y install gcc
yum -y install gcc-c++

## 卸载旧版本
yum -y remove docker docker-common docker-selinux docker-engine

## 安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2

## 设置stable镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

## 更新yum软件包索引
yum makecache fast

## 安装DOCKER CE
yum -y install docker-ce

## 启动docker
systemctl start docker

## 检查安装结果
docker version   
docker run hello-world

## 配置镜像加速
mkdir -p /etc/docker  
vim  /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker

## 卸载 
systemctl stop docker 
yum -y remove docker-ce
rm -rf /var/lib/docker


3.试运行

3.1 配置专属加速

登陆阿里云,在产品与服务->容器镜像服务->镜像加速器 找到专属加速器地址;
将该配置到docker配置(vi /etc/sysconfig/docker)中: other_args="–registry-mirror=https://*****.mirror.aliyuncs.com"

[root@bogon sysconfig]# vi /etc/sysconfig/docker
[root@bogon sysconfig]# service docker restart;
Stopping docker:                                           [  OK  ]
Starting docker:	                                   [  OK  ]

3.2 运行HelloWord


[root@bogon sysconfig]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
482c215f2373: Pull complete 
fd74c3615f76: Pull complete 
Digest: sha256:0ebe6f409b373c8baf39879fccee6cae5e718003ec3167ded7d54cb2b5da2946
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/

1.Docker在本机寻找镜像
1.1 本机有镜像
 以该镜像为模板生成容器实例运行
1.2 本机无镜像
 到Docker Hub上查找该镜像
1.2.1 Docker Hub上有镜像
  下载镜像到本地,以该镜像为模板生成容器实例运行
1.2.2 Docker Hub上无镜像
  返回失败,查不到该镜像

4.其它

4.1 结构

Docker是一个Client-Server结构的系统,Docker守护进程运行在主机上, 然后通过Socket连接从客户端访问,守护进程从客户端接受命令并管理运行在主机上的容器。

4.2 docker VS 虚拟机

列项Docker容器虚拟机VM
操作系统与宿主机共享OS宿主机OS上运行虚拟机OS
存储大小镜像小,便于存储与运输镜像庞大(vmdk等)
运行性能几乎无额外性能损失操作系统额外的CPU,内存消耗
移植性轻便,灵活,适应于Linux笨重,与虚拟化技术耦合度高
硬件亲和性面向软件开发者面向硬件维护者
部署速度快速,秒级较慢,10s以上

(1)docker有着比虚拟机更少的抽象层。由亍docker不需要Hypervisor实现硬件资源虚拟化,运行在docker容器上的程序直接使用的都是实际物理机的硬件资源。因此在CPU、内存利用率上docker将会在效率上有明显优势。

(2)docker利用的是宿主机的内核,而不需要Guest OS。因此,当新建一个容器时,docker不需要和虚拟机一样重新加载一个操作系统内核。仍而避免引寻、加载操作系统内核返个比较费时费资源的过程,当新建一个虚拟机时,虚拟机软件需要加载Guest OS,返个新建过程是分钟级别的。而docker由于直接利用宿主机的操作系统,则省略了返个过程,因此新建一个docker容器只需要几秒钟。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值