Sobes.tech
Middle

How does Docker differ from a virtual machine?

sobes.tech AI

Answer from AI

Docker uses the concept of containers, which are lightweight and share the host operating system kernel. A virtual machine (VM) emulates complete hardware, including its own OS kernel.

Key differences:

  • Isolation: Containers isolate processes at the OS level, VMs isolate at the hardware level.
  • Weight: Containers are significantly lighter and start faster than VMs.
  • Resources: Containers consume fewer resources (RAM, CPU) compared to VMs.
  • Portability: Containers are more portable and easily moved between environments.
  • Hypervisor: VMs require a hypervisor (e.g., VMware, VirtualBox), containers use a container engine (e.g., Docker Engine).

Comparison:

Feature Docker (Container) Virtual Machine (VM)
Isolation OS-level processes Hardware level processes
Weight Light Heavy
Startup Fast Slow
Resource consumption Low High
Portability High Lower
OS Kernel Uses host kernel Has its own kernel
Hypervisor Not required (uses container engine) Required (e.g., VMware, VirtualBox, Hyper-V)

Example Dockerfile structure:

# Using a base image
FROM openjdk:11-jdk-slim

# Copying the application executable into the image
COPY target/myapp.jar app.jar

# Defining the working directory
WORKDIR /app

# Starting the application when the container runs
ENTRYPOINT ["java", "-jar", "app.jar"]