Middle
What are the differences in disk mounting between a virtual machine and a container?
sobes.tech AI
Answer from AI
Virtual Machine:
- Mounts block devices (e.g., virtual disks
.vmdk,.vhd). - Uses standard filesystems (XFS, Ext4, NTFS, etc.) by formatting block devices.
- Mounting occurs at the OS kernel level inside the VM, managed by the hypervisor.
- Various types of mounting are available, including RDM (Raw Device Mapping) for direct access to physical disks.
Container:
- Uses overlay filesystem concepts (AUFS, overlay2).
- Mounts image layers and overlays volumes on top of layers.
- Volume can be:
- host path mount (mounting a directory from the host system).
- named volume (managed by Docker daemon or orchestrator).
- volume driver (plugins for different storage, e.g., Ceph, GlusterFS).
- Mounting is done via chroot/pivot_root mechanism and namespace in the host kernel.
- Container filesystem is formed from image layers and writable layer, onto which volumes can be mounted.
- Container filesystem is ephemeral by default, data is stored only in volumes.
Differences:
| Attribute | Virtual Machine | Container |
|---|---|---|
| Main mechanism | Block device, Filesystem | Overlay FS, Volumes |
| Mount level | OS kernel inside VM, Hypervisor | Host kernel (namespace, chroot) |
| Storage types | Virtual disks, physical disks (RDM) | Host-path, named volumes, drivers |
| Filesystem durability | Depends on disk | Ephemeral (except volumes) |
| Formatting | Required on block device | Filesystem formed from layers and mounts |
# Example of mounting in Docker Compose
volumes:
data_volume: # Named volume
driver: local # Or another driver
logs_volume: # Host path mount
type: bind
source: /var/log/myapp
target: /app/logs
services:
myapp:
image: myapp_image
volumes:
- data_volume:/app/data # Mounting named volume
- logs_volume:/app/logs # Mounting host path