Docker与普通虚拟机不同? [英] How is Docker different from a normal virtual machine?

查看:291
本文介绍了Docker与普通虚拟机不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断重读 Docker文档,以尝试了解Docker和完整VM之间的区别。为了提供一个完整的文件系统,隔离的网络环境等,而不是那么重,它是如何管理的?

I keep rereading the Docker documentation to try to understand the difference between Docker and a full VM. How does it manage to provide a full filesystem, isolated networking environment, etc. without being as heavy?

为什么要将一个软件部署到码头的映像(如果这是正确的术语) )比简单地部署到一致的生产环境更容易?

Why is deploying software to a docker image (if that's the right term) easier than simply deploying to a consistent production environment?

推荐答案

Docker最初使用 LinuX Containers (LXC),但后来切换到 runC (以前称为 libcontainer ),其运行在与其主机相同的操作系统中。这允许它共享大量的主机操作系统资源。此外,它使用分层文件系统( AuFS )并管理网络。

Docker originally used LinuX Containers (LXC), but later switched to runC (formerly known as libcontainer), which runs in the same operating system as its host. This allows it to share a lot of the host operating system resources. Also, it uses a layered filesystem (AuFS) and manages networking.

AuFS是一个分层文件系统,因此您可以拥有一个只读部分和一个写入部分合并在一起。可以将操作系统的公共部分作为只读(并在所有容器之间共享),然后给每个容器自己的挂载进行写入。

AuFS is a layered file system, so you can have a read only part and a write part which are merged together. One could have the common parts of the operating system as read only (and shared amongst all of your containers) and then give each container its own mount for writing.

所以,假设您拥有1张GB容器图片;如果您想使用完整的虚拟机,则需要拥有1 GB GB的x个虚拟机数。使用Docker和AuFS,您可以在所有容器之间共享1 GB的大部分内容,如果您有1000个容器,那么容器操作系统仍然可能只占用1 GB以上的空间(假设它们都运行相同的操作系统图像)。

So, let's say you have a 1 GB container image; if you wanted to use a full VM, you would need to have 1 GB times x number of VMs you want. With Docker and AuFS you can share the bulk of the 1 GB between all the containers and if you have 1000 containers you still might only have a little over 1 GB of space for the containers OS (assuming they are all running the same OS image).

一个完整的虚拟化系统获得分配给它的自己的一组资源,并且进行最小的共享。你得到更多的隔离,但它更重(需要更多的资源)。使用Docker,您可以获得更少的隔离度,但是容器是轻量级的(需要较少的资源)。所以你可以轻松地在主机上运行数千个容器,甚至不会闪烁。尝试这样做,与Xen,除非你有一个很大的主机,我不认为这是可能的。

A full virtualized system gets its own set of resources allocated to it, and does minimal sharing. You get more isolation, but it is much heavier (requires more resources). With Docker you get less isolation, but the containers are lightweight (require fewer resources). So you could easily run thousands of containers on a host, and it won't even blink. Try doing that with Xen, and unless you have a really big host, I don't think it is possible.

一个完整的虚拟化系统通常需要几分钟才能开始,而Docker / LXC / runC容器需要几秒钟,通常甚至不到一秒钟。

A full virtualized system usually takes minutes to start, whereas Docker/LXC/runC containers take seconds, and often even less than a second.

每种类型的虚拟化系统都有优缺点。如果您希望使用有保证的资源进行完全隔离,那么可以使用完整的虚拟机。如果您只是希望将流程相互隔离,并希望在合理大小的主机上运行它们,那么Doc​​ker / LXC / runC似乎是要走的路。

There are pros and cons for each type of virtualized system. If you want full isolation with guaranteed resources, a full VM is the way to go. If you just want to isolate processes from each other and want to run a ton of them on a reasonably sized host, then Docker/LXC/runC seems to be the way to go.

有关更多信息,请查看这组博客文章,它们很好地解释了LXC的工作原理。

For more information, check out this set of blog posts which do a good job of explaining how LXC works.


为什么要将一些软件部署到码头图像(如果这是正确的术语)比简单部署到一致的生产环境更容易?

Why is deploying software to a docker image (if that's the right term) easier than simply deploying to a consistent production environment?

部署一致的生产环境比说起来容易一些。即使您使用 Chef Puppet ,总是有OS更新和其他东西在主机和环境之间变化。

Deploying a consistent production environment is easier said than done. Even if you use tools like Chef and Puppet, there are always OS updates and other things that change between hosts and environments.

Docker使您能够将操作系统快照到共享映像中,并可以轻松在其他Docker主机上部署。本地,dev,qa,prod等:所有相同的图像。确定你可以用其他工具来做到这一点,但是不要那么简单或快速。

Docker gives you the ability to snapshot the OS into a shared image, and makes it easy to deploy on other Docker hosts. Locally, dev, qa, prod, etc.: all the same image. Sure you can do this with other tools, but not nearly as easily or fast.

这是非常好的测试;假设您有成千上万的测试需要连接到数据库,每个测试需要一个原始的数据库副本,并将更改数据。经典的方法是在每次测试后重新设置数据库,使用自定义代码或 Flyway 等工具 - 这可以是非常耗时,意味着测试必须连续运行。然而,使用Docker,您可以创建一个数据库的映像,并为每个测试运行一个实例,然后并行运行所有测试,因为您知道它们都将针对数据库的相同快照运行。由于测试是并行运行的,在Docker容器中,它们可以同时运行在同一个盒子上,并且应该完成得更快。尝试使用完整的虚拟机。

This is great for testing; let's say you have thousands of tests that need to connect to a database, and each test needs a pristine copy of the database and will make changes to the data. The classic approach to this is to reset the database after every test either with custom code or with tools like Flyway - this can be very time-consuming and means that tests must be run serially. However, with Docker you could create an image of your database and run up one instance per test, and then run all the tests in parallel since you know they will all be running against the same snapshot of the database. Since the tests are running in parallel and in Docker containers they could run all on the same box at the same time and should finish much faster. Try doing that with a full VM.

从评论...


有趣!我想我仍然对快照操作系统的概念感到困惑。如果没有,那么做一个操作系统的图像呢?

Interesting! I suppose I'm still confused by the notion of "snapshot[ting] the OS". How does one do that without, well, making an image of the OS?

好吧,我们来看看是否可以解释。您从基础图像开始,然后进行更改,并使用docker提交这些更改,并创建一个图像。此图像仅包含与基数的差异。当您想要运行图像时,您还需要基础,并使用分层文件系统将图像分层在基础上。如上所述,Docker使用AUFS。 AUFS将不同的层合并在一起,你会得到你想要的;你只需要运行它。您可以继续添加越来越多的图像(图层),它将继续仅保存差异。由于Docker通常建立在注册表的现成图像之上,所以您很少需要快照整个操作系统自己。

Well, let's see if I can explain. You start with a base image, and then make your changes, and commit those changes using docker, and it creates an image. This image contains only the differences from the base. When you want to run your image, you also need the base, and it layers your image on top of the base using a layered file system: as mentioned above, Docker uses AUFS. AUFS merges the different layers together and you get what you want; you just need to run it. You can keep adding more and more images (layers) and it will continue to only save the diffs. Since Docker typically builds on top of ready-made images from a registry, you rarely have to "snapshot" the whole OS yourself.

这篇关于Docker与普通虚拟机不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆