Docker Docker の learning and virtual machines

Initially hear Docker, it is to promote as a virtual machine, but it is essentially not a virtual machine

A virtual machine

VM (Virtual Machine) refers to a complete hardware system functions, run a full computer system through software simulation in a completely isolated environment.
Virtual system by creating a new virtual mirror existing operating system, it has a real windows system exactly the same function, into the virtual system, all operations are in this new independent virtual system which conduct can be installed stand-alone software, save data, have their own independent desktop, will not have any impact on the real system, but also a kind of operating system the flexibility to switch between the existing system and virtual images. Virtual systems and traditional virtual machine ( Parallels Desktop  , Vmware , VirtualBox , Virtual PC ) except that: the system does not degrade the performance of Virtual PC, start the virtual system does not boot windows system like that takes time, run programs faster and more convenient; virtual the system can simulate the same conventional operating system environment, the virtual machine can simulate other types of operating systems; and virtual machine instructions need to simulate the underlying hardware, the virtual system is much slower than the speed on the application.
Popular virtual machine software VMware ( VMWare ACE ), Virtual Box (free) and Virtual PC , they can be a multiple virtual computers on a Windows system.

When using an application running multiple virtual machines are isolated, as shown below:

From bottom to top in FIG understanding:

Infrastructure (Infrastructure). It could be your PC, server data center, or cloud host.

The main operating system (Host Operating System). On your PC, it may be running MacOS, Windows or a Linux distribution.

Virtual machine management system (Hypervisor). Using Hypervisor, you can run multiple operating systems different from the above the main operating system. Type 1 Hypervisor has HyperKit support the MacOS, Windows, Hyper-V support, and support for Linux KVM. Hypervisor and type 2 are VirtualBox VMWare.

From the operating system (Guest Operating System). Suppose you need to run three isolated applications, you need to start Hypervisor 3 from the operating system, which is three virtual machines. These virtual machines are very large, perhaps there is 700MB, which means that they will take up 2.1GB of disk space. Worse, they also consume a lot of CPU and memory.

Various dependencies. Each of the operating system needs to install many dependencies. If your application requires connection PostgreSQL, then you need to install libpq-dev; if you use Ruby, then, should you need to install gems; if you use other programming languages, such as Python or Node.js, will need to install the corresponding dependent libraries.

application. After installation dependent, it can be applied in each run separately from the operating system, so that each application is isolated from each other.

Two, Docker container

When running multiple applications using isolated Docker containers, as shown below:

 

The main operating system (Host Operating System). All major Linux distributions can run Docker. For MacOS and Windows, there are some ways to "run" Docker.

Docker daemon (Docker Daemon). Docker daemon replaces the Hypervisor, which is running a background process on top of the operating system, is responsible for managing Docker containers.

Various dependencies. For Docker, all dependent applications are packaged in Docker mirror, Docker Docker containers is based on image creation.

应用。应用的源代码与它的依赖都打包在Docker镜像中,不同的应用需要不同的Docker镜像。不同的应用运行在不同的Docker容器中,它们是相互隔离的。

三、对比虚拟机与Docker

Docker守护进程可以直接与主操作系统进行通信,为各个Docker容器分配资源;它还可以将容器与主操作系统隔离,并将各个容器互相隔离。虚拟机启动需要数分钟,而Docker容器可以在数毫秒内启动。由于没有臃肿的从操作系统,Docker可以节省大量的磁盘空间以及其他系统资源。

因为两者有不同的使用场景,当然也不排除以后它会替代虚拟机。

虚拟机更擅长于彻底隔离整个运行环境。例如,云服务提供商通常采用虚拟机技术隔离不同的用户。

Docker通常用于隔离不同的应用,例如前端,后端以及数据库。

 

容器使用由Linux内核提供的命名空间,大多数人把命名空间认为是一个上下文或域的授权决定(进程X有权访问资源Y)。

如果容器内的进程扫描文件系统来寻找要窃取的东西,它只能找到容器内明确可见的文件。

如果容器内的进程中想尝试做一些恶意的事情,比如打开端口31337后门服务,它不会有多大好处,因为这个端口实际上不会暴露在容器外的任何地方。容器内部的恶意进程不能访问的任何容器外的其他进程的内存。

有几个方法可以摆脱容器的束缚,但这些通常需要容器的root访问权限。

不要以root运行应用程序,通过简单的几个步骤稳固root访问权限。

容器使用cgroup来提供与虚拟机相同级别的资源使用保护机制。容器和虚拟机都可以获取整个网络链接。

容器运行的是不完整的操作系统(尽管它们可以),虚拟机必须运行完整的。

容器比虚拟机使用更少的闲置资源,它们不运行完整的操作系统。

容器在在云硬件(或虚拟机)中可以被复用,就像虚拟机在裸机上可以被复用。

容器需要毫秒分配,虚拟机需要几分钟。所以,你可以另配、重新平衡、释放以及使用容器比虚拟机的迭代更加迅速。

如果每个容器运行的只有一个服务或者数据库,这是比较容易管理的。而且比较容易监控性能,了解故障的影响,并预测成本。

离目标进程越远,隔离会变得更昂贵。虚拟机是伟大的,它通过抽象来增加并行,服务于多操作系统的使用情况以及业界最好的安全性。但对于隔离,它们相当的昂贵,容器提供的隔离就便宜。

服务器虚拟化vs Docker

 

服务器好比运输码头:拥有场地和各种设备(服务器硬件资源)

服务器虚拟化好比作码头上的仓库:拥有独立的空间堆放各种货物或集装箱

(仓库之间完全独立,独立的应用系统和操作系统)

Docker比作集装箱:各种货物的打包

Docker有着小巧、迁移部署快速、运行高效等特点,但隔离性比服务器虚拟化差:不同的集装箱属于不同的运单(Docker上运行不同的应用实例),相互独立(隔离)。但由同一个库管人员管理(主机操作系统内核),因此通过库管人员可以看到所有集装箱的相关信息

 

Guess you like

Origin www.cnblogs.com/xietianjiao/p/11271168.html