What are the differences between a VM image and a Docker image?
This question already has an answer here:
These are some differences between a docker and a VM image which I could list out:
1. Snapshot process is faster in Docker than VMs
We generally start with a base image, and then make our changes, and commit those changes using docker, and it creates an image. This image contains only the differences from the base. When we want to run our image, we also need the base, and it layers our image on top of the base using a layered file system. File system merges the different layers together and we get what we want, and we just need to run it. Since docker typically builds on top of ready-made images from a registry, we rarely have to "snapshot" the whole OS ourself. This ability of Dockers to snapshot the OS into a common image also makes it easy to deploy on other docker hosts.
2. Startup time is less for Docker than VMs
A virtual machine usually takes minutes to start, but containers takes seconds, and sometime even less than a second.
4. Docker images have more portability
Docker images are composed of layers. When we pull or transfer an image, only the layers we haven't yet in cache are retrieved. That means that if we use multiple images based on the same base Operating System, the base layer is created or retrieved only once. VM images doesn't have this flexibility.
5. Docker provides versioning of images
We can use the docker commit command. We can specify two flags: -m
and -a.
The -m
flag allows us to specify a commit message, much like we would with a commit on a version control system:
$ sudo docker commit -m "Added json gem" -a "Kate Smith"
0b2616b0e5a8 ouruser/sinatra:v2
4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c
6. Docker images do not have states
In Docker terminology, a read-only Layer is called an image. An image never changes. Since Docker uses a Union File System, the processes think the whole file system is mounted read-write. But all the changes go to the top-most writeable layer, and underneath, the original file in the read-only image is unchanged. Since images don't change, images do not have state.
7. VMs are hardware-centric and docker containers are application-centric
Let's say we have a container image that is 1GB in size. If we wanted to use a Full VM, we would need to have 1GB times x number of VMs you want. In docker container we can share the bulk of the 1GB and if you have 1000 containers we still might only have a little over 1GB of space for the containers OS, assuming they are all running the same OS image.
8. Supported image formats
Docker images:
VM images:
上一篇: 我应该使用Docker在Linux操作系统中创建Linux操作系统吗?
下一篇: VM镜像和Docker镜像有什么区别?