{"id":13359,"date":"2022-03-14T12:30:00","date_gmt":"2022-03-14T11:30:00","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=13359"},"modified":"2023-05-15T02:23:19","modified_gmt":"2023-05-15T00:23:19","slug":"containers-vs-virtual-machines","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/containers-vs-virtual-machines\/","title":{"rendered":"Containers vs Virtual Machines (Cloud Explained Series)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg\" alt=\"Cover picture article on containers\" class=\"wp-image-13361\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container-600x315.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container-768x403.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Both virtual machines and containers are routinely used for handling cloud workloads. Our <a href=\"https:\/\/contabo.com\/blog\/how-does-virtualization-work\/\" target=\"_blank\" rel=\"noreferrer noopener\">previous article<\/a> described how virtual machines work, today we\u2019re going to focus on their lightweight relative \u2013 containers. But before we start with containers, let\u2019s quickly sum up the previous article:<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-are-virtual-machines-again\">What are Virtual Machines, Again?<\/h2>\n\n\n\n<p>Virtual machines are fully independent virtual computers that allow you to perform all necessary operations in the same way as on your non-virtual OS. Virtual machines have their own hardware capacity &#8211; a certain number of CPUs, RAM and many other parameters.<\/p>\n\n\n\n<p>We explained that modern virtualization is performed with a software called hypervisor. Hypervisors are responsible for distributing hardware resources to guest machines \u2013 sometimes one virtual machine uses more resources, sometimes the other one demands more computing power. Because it\u2019s easy to create many virtual machines on one server and share resources, virtualization has become a way to reduce company\u2019s expenses. Instead of purchasing the whole physical server, it\u2019s possible to order just a small slice of the overall capacity in the form of VPS.<\/p>\n\n\n\n<p>There are many different terms describing the same concept \u2013 virtual machines, virtual computers, cloud instances, VPS. Some companies have their own product names like Amazon\u2019s EC2 or Digital Ocean\u2019s Droplet.<\/p>\n\n\n\n<p>If you haven\u2019t done so already, we recommend that you read our <a href=\"https:\/\/contabo.com\/blog\/how-does-virtualization-work\/\" target=\"_blank\" rel=\"noreferrer noopener\">article on virtualization<\/a> first. It will help you to better understand the containers as well.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-linux-container\">What is a Linux Container?<\/h2>\n\n\n\n<p>Containers are a form of virtualization that is more lightweight and minimalistic than virtual machines. Containers are native for Linux \u2013 they are built directly into its kernel, and they use the same resources as the host OS. To some extent running containers is similar to running any other application on your Linux<\/p>\n\n\n\n<p>Installing a container can be done with a single command \u2013 the system downloads a distribution image and installs it on the computer. Then the kernel starts allocating resources to this new instance. Linux kernel plays the same role as hypervisor with virtual machines &#8211; it sends only that much power to individual containers that they really need.<\/p>\n\n\n\n<p>At first glance, containers look like fully fledged virtual instances. For instance, the popular Alpine image contains the familiar home, root, proc and other folders:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1473\" height=\"57\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/alpine-file-structure.png\" alt=\"Alpine file system\" class=\"wp-image-13366\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/alpine-file-structure.png 1473w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/alpine-file-structure-600x23.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/alpine-file-structure-768x30.png 768w\" sizes=\"auto, (max-width: 1473px) 100vw, 1473px\" \/><\/figure>\n\n\n\n<p>However, containers are not a fully independent operating system. They are just a process running on the Linux kernel of the host system. They contain only the bare essentials that allow them to run your chosen application. For example, the aforementioned Alpine container has by default only 5MB, while the image for the whole operating system usually takes several Gigabytes (3GB in case of a standard Ubuntu 20.04 image). Containers are portable and run in the same way no matter what computer they are currently installed on.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"470\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/VMvsCONT.png\" alt=\"virtual machines vs containers comparison\" class=\"wp-image-13439\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/VMvsCONT.png 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/VMvsCONT-600x235.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/VMvsCONT-768x301.png 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Containers are an important part of the modern DevOps approach, allowing developers to release products faster and update them continuously. You will learn more about DevOps in the next article of Cloud Explained Series.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-containers-vs-virtual-machines\">Containers vs Virtual Machines<\/h2>\n\n\n\n<p>In the last several years, many companies have moved their applications from virtual machines to containers. Yet despite all the hype, virtual machines are not likely to be fully substituted by containers in the future. Those are complementary technologies, not rivals \u2013 containers and virtual machines are often used in the same cloud infrastructure.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><\/td><td><strong>VMs<\/strong><\/td><td><strong>Containers<\/strong><\/td><\/tr><tr><td>Image<\/td><td>All included<\/td><td>Bare essentials<\/td><\/tr><tr><td>Kernel<\/td><td>Independent of Host System OS<\/td><td>Shared with the Host System OS<\/td><\/tr><tr><td>Provisioning<\/td><td>In minutes<\/td><td>In seconds<\/td><\/tr><tr><td>Virtualization<\/td><td>Hardware-based<\/td><td>OS-based<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Let\u2019s look closer at some of the <em>advantages and disadvantages<\/em> of both containers and virtual machines:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-virtual-machines-the-whole-os\">Virtual Machines: The Whole OS<\/h3>\n\n\n\n<p>Container images contain just the bare essentials, while VM runs on an operating system that is equal to a standard physical computer. VMs are more suitable in providing the whole virtual environment, for example as our <a href=\"https:\/\/contabo.com\/en\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS<\/a> instances.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-containers-less-storage-required\">Containers: Less Storage Required<\/h3>\n\n\n\n<p>Some estimates say that you can run as many as<a href=\"https:\/\/www.zdnet.com\/article\/what-is-docker-and-why-is-it-so-darn-popular\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> four-to-six times more containers<\/a> occupying the same space that would normally take virtual machines using Xen or KVM hypervisors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-containers-instantly-ready\">Containers: Instantly Ready<\/h3>\n\n\n\n<p>Containers are quickly installed by just one or a couple of commands. Since they use the kernel of the host OS, there is no delay caused by booting when starting a container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-containers-uniform-environment\">Containers: Uniform Environment<\/h3>\n\n\n\n<p>Containers behave consistently on every computer.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-decision-factor-when-is-container-an-dis-advantage\">Decision factor: When is Container an (Dis)Advantage<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-testing-apps\">Testing apps<\/h3>\n\n\n\n<p>Containers allow developers to quickly test new applications on many different operating systems. Installing a new version of an operating system is much faster than with virtual machines.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-microservice-architecture\">Microservice Architecture<\/h3>\n\n\n\n<p>Containers are perfectly suited to serve as tiny \u201cone task\u201d instances. But microservice architecture often relies on a mix of virtual machines and containers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-databases\">Databases<\/h3>\n\n\n\n<p>Using containers to deploy traditional databases like MySQL can be complicated:<\/p>\n\n\n\n<figure class=\"wp-block-image alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/02\/MicrosoftTeams-image-17-edited-1.jpg\" alt=\"Tino profile picture\" class=\"wp-image-13201\" width=\"220\" height=\"220\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/02\/MicrosoftTeams-image-17-edited-1.jpg 1108w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/02\/MicrosoftTeams-image-17-edited-1-600x600.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/02\/MicrosoftTeams-image-17-edited-1-150x150.jpg 150w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/02\/MicrosoftTeams-image-17-edited-1-768x768.jpg 768w\" sizes=\"auto, (max-width: 220px) 100vw, 220px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-expert-s-opinion-tino-lehnig-cloud-architect\"><strong>Expert\u2019s opinion: Tino Lehnig, Cloud Architect<\/strong><\/h4>\n\n\n\n<p><em>\u201cContainers work best for applications that are state-less, meaning they don\u2019t save any<\/em> <em>persistent data inside. Similar applications can be scaled easily just by deploying more of the same code. Database apps are the polar opposite \u2013 database entries need to be permanently available and scaling requires careful configuration. There is dedicated database orchestration software that is already designed to take this factor into consideration. Adding container orchestration to this mix is usually not worth the effort.\u201d<\/em><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-docker\">Docker<\/h2>\n\n\n\n<p>Docker is currently the most popular container engine on the market. It has gradually replaced the old LXC and other engines. While there are other viable alternatives today, it\u2019s still hard to imagine talking about containers without mentioning Docker. Before we start, let&#8217;s clarify three key terms:<\/p>\n\n\n\n<p><strong>Important Terms<\/strong><br><em>Parent image<\/em> \u2013 is the read-only standard image you download first. That can be anything like Ubuntu OS container, LAMP container, WordPress container\u2026<\/p>\n\n\n\n<p><em>Image<\/em> \u2013 once you start working on the parent image, it becomes your own project. This is the one you share with your colleagues.<\/p>\n\n\n\n<p><em>Container <\/em>\u2013 is the environment itself for running all the images. Containers cannot run without an image.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-do-developers-use-docker\">How do Developers Use Docker?<\/h3>\n\n\n\n<p>To get you a better idea, let\u2019s look at a typical setup using Docker. Let\u2019s assume in this example that we don\u2019t use any container services, as we always encourage our customers to rent a <a href=\"https:\/\/contabo.com\/en\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS<\/a>, <a href=\"https:\/\/contabo.com\/en\/vds\/\" target=\"_blank\" rel=\"noreferrer noopener\">VDS<\/a> or <a href=\"https:\/\/contabo.com\/en\/dedicated-servers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Dedicated Server<\/a> and build containerization in-house:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-installing-docker\">Installing Docker<\/h3>\n\n\n\n<p>Although containers use a technology that is already included in every Linux, users have to install the container engine first. The installation can be done easily via command line based on the particular <a href=\"https:\/\/docs.docker.com\/engine\/install\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">OS<\/a>.<\/p>\n\n\n\n<p>Contabo customer can save time and install Docker while installing or re-installing the OS on their <a href=\"https:\/\/contabo.com\/en\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS<\/a>, <a href=\"https:\/\/contabo.com\/en\/vds\/\" target=\"_blank\" rel=\"noreferrer noopener\">VDS<\/a> or <a href=\"https:\/\/contabo.com\/en\/dedicated-servers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Dedicated Server<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"292\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/installing-docker-CCP.png\" alt=\"Installing Docker with Contabo\" class=\"wp-image-13376\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/installing-docker-CCP.png 812w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/installing-docker-CCP-600x216.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/installing-docker-CCP-768x276.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p><span style=\"text-decoration: underline;\"> <\/span><em>Reminder: Backup your data first before re-installing your OS, there are no automatic backups performed.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-downloading-the-container-image\">Downloading the Container Image<\/h3>\n\n\n\n<p>There are public and private Docker repositories (libraries) where developers can browse and download an image.<\/p>\n\n\n\n<p>The most popular public repository is <a href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Docker Hub<\/a>. The repository already includes a command that downloads the image to the computer, for instance:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"517\" height=\"146\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/docker-pull-example.png\" alt=\"Example of a docker pull\" class=\"wp-image-13378\"\/><\/figure>\n\n\n\n<p>Docker Hub aside, many companies (including us) run private repositories for their own internal images.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-working-with-containers\">Working with Containers<\/h3>\n\n\n\n<p>Once the developer downloads and executes the image, they can upload the data inside of the container or edit various parameters:<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.docker.com\/get-started\/\" rel=\"nofollow\">https:\/\/docs.docker.com\/get-started\/<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-uploading-the-work-into-a-repository\">Uploading the Work into a Repository<\/h3>\n\n\n\n<p>Once the work is done, the developer exports the image to the respective repository. Then they can just send a link to their colleagues or publish the image for everyone to use.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Despite all the hype, virtual machines are not likely to be fully substituted by containers in the future. Those are complementary technologies, not rivals \u2013 containers and virtual machines are often used in the same cloud infrastructure.<\/p>\n","protected":false},"author":49,"featured_media":13361,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[1481],"class_list":["post-13359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container-150x150.jpg",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container-600x315.jpg",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container-768x403.jpg",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_Container.jpg",1200,630,false]},"uagb_author_info":{"display_name":"Petr","author_link":"https:\/\/contabo.com\/blog\/author\/petr\/"},"uagb_comment_info":0,"uagb_excerpt":"Despite all the hype, virtual machines are not likely to be fully substituted by containers in the future. Those are complementary technologies, not rivals \u2013 containers and virtual machines are often used in the same cloud infrastructure.","authors":[{"term_id":1481,"user_id":49,"is_guest":0,"slug":"petr","display_name":"Petr","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/3a3991d3f2f2e482436c374c378ac5dec17a1e02bd60ef356744005bc37a02e7?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=13359"}],"version-history":[{"count":1,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13359\/revisions"}],"predecessor-version":[{"id":17021,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13359\/revisions\/17021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/13361"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=13359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=13359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=13359"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}