ASPECT | DOCKER | VIRTUAL MACHINE |
ARCHITECTURE | Shares host OS kernel, runs as an isolated process | Each VM includes a guest OS on top of a hypervisor |
STARTUP TIME | It takes just seconds to startup | Takes few minutes to startup |
RESOURCE USAGE | Light weight (uses less CPU cycles and memory) | usually heavier than a docker |
PORTABILITY | highly portable across several environments | less portable as it might be dependent on CPU |
ISOLATION | Process level isolation only | Completely OS level isolation |
SECURITY | less secure as it shares kernels | more secure as the OS is separate |
USE CASE | good option for microservices, CI/CD and cloud-native apps | good for running more than one OS or legacy systems |
STORAGE SIZE | pretty compact (usually in several MBs) | large (in GBs) |
PERFORMANCE | near-native performance | slightly 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-
- ISOLATION- each test runs in a disposable environment.
- CONSISTENT- same setup across local and CI environments.
- REALISTIC- tests can be performed on actual services rather than in-memory substitutes.
- 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 |
VOLUMES | managed by docker, /var/lib//docker/volumes (linux). |
BIND MOUNTS | link a host directory to a container path, more control, but less portable |
TMPFS MOUNTS | stored in memory only, good for sensitive or temporary data |
MANAGING VOLUMES
- LIST VOLUME- docker volume is
- INSPECT A VOLUME- docker volume inspect mydata
- REMOVE A VOLUME- docker volume rm mydata
- CLEAN UNUSED VOLUME- docker system prune –volume
WHEN TO USE VOLUME
- Storing database files
- sharing data between containers
- backing up application state
- avoiding data loss during container updates