An Overview of Virtual Machine v.s. Docker v.s. Kubernetes

Hanwen Zhang
4 min readJul 15, 2023

--

Docker is a lighter, quicker running environment than a Virtual Machine (VM), which makes it easy to create, deploy, and run apps using containers.

Docker vs. Virtual Machine

A virtual machine virtualizes the computer system, it has its version of a file system, registry, and virtualized hardware. VM allows you to go back to the original state based on the snapshot you took initially, which is very useful to have the application configured in a particular way so that you can always start from the initial checkpoint.

The Docker container is an efficient way to create virtual machines that do not need multiple operational systems, you just need to create one snapshot of the libraries and applications in a single shared OS.

Docker packages software so it can run on any hardware, a use case for using Docker is to set up a new project, and have the same setup across different systems, same setup across different projects, or developers

Components

  • Container: example — have MongoDB in a container, react frontend in a container, node express server in a container
  • Image: blueprint — contains all the information that our container needs to build a container the same way across all systems
  • Volume: hold the data of your containers, data that changes are on the volumes if your app is on static containers
  • Networking: allow all the items above to communicate with each other
  • Dockerfile: create an image based on the instructions of your Dockerfile

Why Docker

Docker scales (structures) your apps very easily, and comes with a whole set of tools for deploying across many clusters, you can take your instances of each micro-service that you have in each container, and you can specify how many of the resources of each machine you want, specify rules about how they should scale, what should happen if they crash, and make everything scalable.

Kubernetes

Kubernetes works like Docker, but Docker is just one container, Kubernetes is like a cluster, it has multiple containers (each running its own node), and hosting images that can make deployment easier.

Kubectl: command line tool (open shell) — check Kubectl cheatsheet

Kubectx: make it easy to select a cluster (namespace) and create aliases

Swarm vs Kubernetes

Kubernetes offers similar tools to Swarm like clustering, scaling, scheduling, and deploying large clusters. Swarm is a tool that is tight with docker whereas Kubernetes is an industry-standard, more customized tool.

Deployment

Docker supports deploying containers on Azure ACI and AWS ECS. You can also deploy your application to Kubernetes if you have enabled Kubernetes in Docker Desktop.

To enable Kubernetes in Docker:

  1. From the Docker menu, select Settings.
  2. Select Kubernetes and click Enable Kubernetes

Use Docker

Why use a Virtual Machine? VM is just like a computer system, and we can run multiple OS environments on a single physical machine.

Why use Docker? Docker creates VMs over one single OS environment, so-called the Container.

Why use Kubernetes? Kubernetes creates multiple Containers and gathers them in a cluster.

To use Docker in your application, you would set up a Dockerfile and a docker-compose.yml. Check the Docker documentation link.

After setting up the correct configuration and installation, run:

docker ps           #containers that runs in your machine linked to an image
docker system prune
docker-compose up -d <namespace>
docker pull sql
make init

Docker commands reference — 50 docker commands & docker.html

The article is inspired by Blog Post.

--

--

Hanwen Zhang

Full-Stack Software Engineer at a Healthcare Tech Company | Document My Coding Journey | Improve My Knowledge | Share Coding Concepts in a Simple Way