Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Ubuntu docker image not a VM [duplicate]

I get the big difference between VMs and containers. But that has me confused about how an Ubuntu container can even exist. It feels contradictory to me since Ubuntu is an OS.

https://hub.docker.com/_/ubuntu

Isn't this an entire guest OS? So what makes this a container over a VM? Or is the line between container and VM blurred?

I've tried googling this but the only results I find are the classic VM vs container answers which isn't really what I'm asking I don't think.

Edit - I've updated to try further clarify my question.

like image 579
Winston Henke Avatar asked Dec 29 '18 18:12

Winston Henke


People also ask

Why container is not a virtual machine?

The key differentiator between containers and virtual machines is that virtual machines virtualize an entire machine down to the hardware layers and containers only virtualize software layers above the operating system level.

What is the difference between VM and Docker container?

Virtual machines have a host operating system and a guest operating system inside each VM. The guest OS can be any OS, such as Linux or Windows, irrespective of the host OS. In contrast, Docker containers are hosted on a single physical server with the host OS shared among them.

Can I run a Ubuntu VM on Docker?

This template allows you to deploy an Ubuntu VM with Docker (using the Docker Extension). You can later SSH into the VM and run Docker containers.


1 Answers

Docker is a new way of running applications in isolated lightweight containers. Even though they are isolated, they can integrate with other components.

Efficiency isn't the only gain. When you package your application to run in Docker, you get portability. You can run your app in a Docker container on your laptop, and it will behave in exactly the same way on a server in your data center and on a virtual machine (VM) in any cloud.

The other big motivator is security. Containers add secure isolation between applications, so you can be confident that if one application is compromised, the attacker can't move on to compromise other apps on the same host.

When you package your applications as Docker images, they all have the same shape—you can deploy, manage, secure, and upgrade them all in the same way.

To answer your question:

  • Each docker container runs its own lightweight VM, so the line between a regular VM is blurred, except the fact that docker containers aren't meant for GUI applications like regular VM's.

  • You assumed wrong. You need to include an OS in your Dockerfile and afterwards the application code. However, depending on your application, different sizes of OS images exist on Docker Hub, like the windows nanoserver, if you only have a simple console application that you want to run. Then you don't need a VM with the full scale OS. Another thing you can do is running staged builds in your dockerfile that will compile your application and only include the Runtime environment in your image, effectively reducing its size.

  • Docker is mainly meant to dockerrize new and legacy applications, meaning splitting them up in logically separated containers. When an application is dockerrized, it gains benefits like security, separation of dependencies, zero downtime maintenance, continuous integration pipelines, portability, efficiency etc. You can't containerize an application using a regular VM. The purposes and builds of docker containers and regular VM's are different.

I can recommend the following book if you are working with windows containers to get a better overview of the purpose of docker: https://www.packtpub.com/virtualization-and-cloud/docker-windows

If not then packt offers other books for docker on linux.

I hope this answers your question :)

like image 164
hatati Avatar answered Oct 08 '22 01:10

hatati