Docker入门(一)-安装

一、Docker简介

什么是Docker?

Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目。它基于 Google 公司推出的 Go 语言实现。项目后来加入了 Linux 基金会,遵从了 Apache 2.0 协议,项目代码在GitHub上进行维护。

Docker 自开源后受到广泛的关注和讨论,以至于 dotCloud 公司后来都改名为 Docker Inc。Redhat 已经在其 RHEL6.5 中集中支持 Docker;Google 也在其 PaaS 产品中广泛应用。

Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。Docker 的基础是 Linux 容器(LXC)等技术。

在 LXC 的基础上 Docker 进行了进一步的封装,让用户不需要去关心容器的管理,使得操作更为简便。用户操作 Docker 的容器就像操作一个快速轻量级的虚拟机一样简单。

简单来说,Docker类似与VM的虚拟机,只是实现的层面不同。Docker是基于操作系统上的轻量级虚拟化,速度更快。而传统的虚拟机VM是基于物理层面的硬件虚拟化,运行的效率比较低

详细解释可参考:https://www.jianshu.com/p/3bfa8d09bc8b

Docker的组成?

了解Docker的组成首先要清楚三个关键概念

  • 仓库(Repository)
  • 镜像(Image)
  • 容器(Container)

为了更加形象深刻的解析这三个词,我们来打个不太恰当的比方:比如玩过LOL的就知道,如果我想玩一个名叫"疾风剑豪-亚索"的英雄(镜像),那么首先就要有足够的金币,然后到游戏商城(仓库)购买。你就可以在游戏中使用这个英雄(容器),而且皮肤,天赋都是可以根据自己的需要去设置的。

二、Docker安装

1.查看系统的内核版本,系统使用的是CentOS7.7_x64

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

2.设置阿里云网络yum源

略......

3.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的。(注意在生产环境中如果没有特殊情况,不要随便使用yum update更新系统内核

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
......

4.设置Docker的yum源

[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

 5.可以查看所有仓库中所有的Docker版本,并选择特定版本安装

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
 * extras: mirrors.aliyun.com
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
......

6.安装Docker,命令:yum install docker-ce-版本号,我选的是17.12.1.ce,如下:

[root@localhost ~]# yum install docker-ce-17.12.1.ce -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:17.12.1.ce-1.el7.centos will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: docker-ce-17.12.1.ce-1.el7.centos.x86_64
--> Processing Dependency: libcgroup for package: docker-ce-17.12.1.ce-1.el7.centos.x86_64
......

7.开启Docker服务,并设置开机自启动

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

8.查看Docker是否成功安装并运行(显示server和client说明安装Docker成功!

[root@localhost ~]# docker version
Client:
 Version:    17.12.1-ce
 API version:    1.35
 Go version:    go1.9.4
 Git commit:    7390fc6
 Built:    Tue Feb 27 22:15:20 2018
 OS/Arch:    linux/amd64

Server:
 Engine:
  Version:    17.12.1-ce
  API version:    1.35 (minimum version 1.12)
  Go version:    go1.9.4
  Git commit:    7390fc6
  Built:    Tue Feb 27 22:17:54 2018
  OS/Arch:    linux/amd64
  Experimental:    false

猜你喜欢

转载自www.cnblogs.com/ashjo009/p/12221348.html