Skip to content
Fix Code Error

How is Docker different from a virtual machine?

March 13, 2021 by Code Error
Posted By: Anonymous

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?

Solution

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 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.

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 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).

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.

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

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.

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?

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 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.

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.

From comments…

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?

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.

Answered By: Anonymous

Related Articles

  • Can Windows Containers be hosted on linux?
  • How to remove MySQL completely with config and…
  • Using GPU from a docker container?
  • From inside of a Docker container, how do I connect…
  • How to connect to a docker container from outside…
  • Virtual Memory Usage from Java under Linux, too much…
  • How to mount host volumes into docker containers in…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Aurelia bundling issue with virtual directory
  • How to install the Raspberry Pi cross compiler on my…
  • How to remove old and unused Docker images
  • Rebuild Docker container on file changes
  • insert tables in dataframe with years from 2000 to…
  • What are some resources for getting started in…
  • What is the (best) way to manage permissions for…
  • How to correctly link php-fpm and Nginx Docker containers?
  • Proper use of the IDisposable interface
  • Docker command can't connect to Docker daemon
  • How to solve Internal Server Error in Next.Js?
  • Change the location of the ~ directory in a Windows…
  • How to change Windows 10 interface language on…
  • DAX Function Using Variables for Efficiency Purposes
  • Logging best practices
  • Get operating system info
  • How to copy files inside a local virtual machine or…
  • Docker Networking - nginx: [emerg] host not found in…
  • How do you list volumes in docker containers?
  • Compiling an application for use in highly…
  • docker command not found even though installed with apt-get
  • What are the nuances of scope prototypal /…
  • How to create User/Database in script for Docker Postgres
  • What are the calling conventions for UNIX &…
  • Cannot connect to the Docker daemon on macOS
  • Should I use Vagrant or Docker for creating an…
  • smallest value greater than N in fibonacci series in python
  • Runing vue/cli app under docker simple index.html is opened
  • Difference between DTO, VO, POJO, JavaBeans?
  • Xamarin iOS new StackTrace() kills App: Assertion…
  • How to deal with persistent storage (e.g. databases)…
  • How do I connect to this localhost from another…
  • Docker compose fails to start a service with an…
  • IIS VirtualDirectories, and accessing their contents…
  • Starting Docker as Daemon on Ubuntu
  • jmxterm: "Unable to create a system terminal" inside…
  • How to access host port from docker container
  • Creating dataframe with lambda &…
  • How can I get docker running in Jenkins nodes which…
  • SSH into Azure App Service for Docker Container
  • How to set up webpack-hot-middleware in an express app?
  • How to list containers in Docker
  • Continuous Integration vs. Continuous Delivery vs.…
  • What is the runtime performance cost of a Docker container?
  • Why does C++ code for testing the Collatz conjecture…
  • How do you read a Python Traceback error?
  • Extracting stuffs from my Jenkins container docker…
  • What's the best way of scraping data from a website?
  • NextJS deploy to a specific URL path
  • Exploring Docker container's file system
  • Docker Compose wait for container X before starting Y
  • data.table vs dplyr: can one do something well the…
  • What is an application binary interface (ABI)?
  • Best practice for Django project working directory structure
  • Virtual/pure virtual explained
  • Docker Compose network_mode and port_binding…
  • How to remove old Docker containers
  • Benefits of deploying using docker-compose
  • Docker compose build time args from file
  • Error message "Forbidden You don't have permission…
  • How to fix docker: Got permission denied issue
  • Iterator invalidation rules
  • Azure Availability Zone ARM Config
  • Assembly code vs Machine code vs Object code?
  • The model backing the 'ApplicationDbContext' context…
  • Abstract Class vs Interface in C++
  • Docker remove TAG images
  • Terraform Azure Container Instance Dynamic Volume -…
  • How to get docker-compose to always re-create…
  • How does PHP 'foreach' actually work?
  • Pandas create the new columns based on the distinct…
  • What are the differences between virtual memory and…
  • docker containers on AWS now do not start until I…
  • There is already an object named in the database
  • Text size and different android screen sizes
  • Difference between a virtual function and a pure…
  • Start redis-server with config file
  • Vuejs 2: debounce not working on a watch option
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • Why are ARGS specified in `docker-compose.yml`…
  • Fastest way to iterate over all the chars in a String
  • How to download and save an image in Android
  • What is a NullReferenceException, and how do I fix it?
  • Making a grading calculator using javascript
  • Docker container will automatically stop after…
  • Trying to get a headless WordPress to do hot…
  • Simplest way to create Unix-like continuous pipeline…
  • Can't connect to docker from docker-compose
  • What are the real-world strengths and weaknesses of…
  • What is the difference between VFAT and FAT32 file systems?
  • Docker compose, running containers in net:host
  • Implementing autocomplete

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Command to collapse all sections of code?

Next Post:

Where does npm install packages?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error