How is Docker different from a virtual machine?

前端 未结 20 2651
闹比i
闹比i 2020-11-21 22:36

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 network

20条回答
  •  终归单人心
    2020-11-21 23:26

    1. Lightweight

    This is probably the first impression for many docker learners.

    First, docker images are usually smaller than VM images, makes it easy to build, copy, share.

    Second, Docker containers can start in several milliseconds, while VM starts in seconds.

    2. Layered File System

    This is another key feature of Docker. Images have layers, and different images can share layers, make it even more space-saving and faster to build.

    If all containers use Ubuntu as their base images, not every image has its own file system, but share the same underline ubuntu files, and only differs in their own application data.

    3. Shared OS Kernel

    Think of containers as processes!

    All containers running on a host is indeed a bunch of processes with different file systems. They share the same OS kernel, only encapsulates system library and dependencies.

    This is good for most cases(no extra OS kernel maintains) but can be a problem if strict isolations are necessary between containers.

    Why it matters?

    All these seem like improvements, not revolution. Well, quantitative accumulation leads to qualitative transformation.

    Think about application deployment. If we want to deploy a new software(service) or upgrade one, it is better to change the config files and processes instead of creating a new VM. Because Creating a VM with updated service, testing it(share between Dev & QA), deploying to production takes hours, even days. If anything goes wrong, you got to start again, wasting even more time. So, use configuration management tool(puppet, saltstack, chef etc.) to install new software, download new files is preferred.

    When it comes to docker, it's impossible to use a newly created docker container to replace the old one. Maintainance is much easier!Building a new image, share it with QA, testing it, deploying it only takes minutes(if everything is automated), hours in the worst case. This is called immutable infrastructure: do not maintain(upgrade) software, create a new one instead.

    It transforms how services are delivered. We want applications, but have to maintain VMs(which is a pain and has little to do with our applications). Docker makes you focus on applications and smooths everything.

提交回复
热议问题