DOCKER VS VIRTUAL MACHINES

ASPECTDOCKERVIRTUAL MACHINE
ARCHITECTUREShares host OS kernel, runs as an isolated processEach VM includes a guest OS on top of a hypervisor
STARTUP TIMEIt takes just seconds to startupTakes few minutes to startup
RESOURCE USAGELight weight (uses less CPU cycles and memory)usually heavier than a docker
PORTABILITYhighly portable across several environmentsless portable as it might be dependent on CPU
ISOLATIONProcess level isolation onlyCompletely OS level isolation
SECURITYless secure as it shares kernelsmore secure as the OS is separate
USE CASEgood option for microservices, CI/CD and cloud-native appsgood for running more than one OS or legacy systems
STORAGE SIZE pretty compact (usually in several MBs)large (in GBs)
PERFORMANCEnear-native performanceslightly overhead due to virtualization

CI/CD WITH DOCKER- AUTOMATING THE WORK FLOW

CI/CD stands for Continuous Integration and Continuous Deployment/Delivery, a modern DevOps practice that automates the process of building, testing, and deploying code. When paired with Docker, it becomes even more powerful, enabling consistent, reproducible environments across every stage of development.

Docker enhances CI/CD pipelines by-

Ensuring consistency across dev, test, and production environments

Speeding up builds and deployments with lightweight containers

Isolating jobs to prevent conflicts and improve security

Simplifying rollback with versioned Docker images

Real-World Tools That Pair Well

Jenkins: Popular for custom pipelines with Docker agents

GitHub Actions: Easy to integrate with Docker workflows

GitLab CI/CD: Built-in Docker support

CircleCI: Optimized for container-based pipelines

TESTING IN CONTAINERS

Testing in containers using in docker is a very good approach to ensure that the application runs properly and correctly in environments that nearly mimic production. there is a library called TestContainers that can be used to perform some real services (like databases, message brokers etc.) inside the docker containers during tests.

SOME OF ITS FEATURES INCLUDE-

  1. ISOLATION- each test runs in a disposable environment.
  2. CONSISTENT- same setup across local and CI environments.
  3. REALISTIC- tests can be performed on actual services rather than in-memory substitutes.
  4. AUTOMATIC- Containers are started and stopped programmatically.

DOCKER VOLUMES

Docker volumes refer to the persistent storage mechanisms which are managed by docker. Unlike the ephemeral nature of containers (which might losses data when stopped or removed ),now these volumes allow this type of data to not be stopped or removed while the containers restart, rebuilt or removed.

NEED OF USING THE DOCKER VOLUMES

  • Container Independence– Volumes exist outside the container lifecycle.
  • Performance– Faster than writing to a container’s writable layer.
  • Portability– Easily shared across containers and backed up.

TYPES OF DOCKER STORAGE

TYPES DESCRIPTION
VOLUMESmanaged by docker, /var/lib//docker/volumes (linux).
BIND MOUNTSlink a host directory to a container path, more control, but less portable
TMPFS MOUNTSstored in memory only, good for sensitive or temporary data

MANAGING VOLUMES

  1. LIST VOLUME- docker volume is
  2. INSPECT A VOLUME- docker volume inspect mydata
  3. REMOVE A VOLUME- docker volume rm mydata
  4. CLEAN UNUSED VOLUME- docker system prune –volume

WHEN TO USE VOLUME

  1. Storing database files
  2. sharing data between containers
  3. backing up application state
  4. avoiding data loss during container updates

Leave a Reply

Your email address will not be published. Required fields are marked *