Virtual Machines run on a hypervisor such as VirtualBox or VMware. Each VM includes:
Architecture: Host OS → Hypervisor → Guest OS → Applications
Characteristics:
Containers run using Docker Engine and share the host OS kernel.
Architecture: Host OS → Docker Engine → Containers → Applications
Characteristics:
| Feature | Virtual Machine | Container |
|---|---|---|
| OS | Full Guest OS | Shared Kernel |
| Boot Time | Minutes | Seconds |
| Size | Large (GBs) | Small (MBs) |
| Isolation | Strong | Process-Level |
| Performance | Slower | Faster |
Check Docker Version: docker –version
Pull Image: docker pull nginx
Run Container: docker run -d -p 8080:80 nginx
List Running Containers: docker ps
List All Containers: docker ps -a
List Images: docker images
Stop Container:
docker stop
Remove Container:
docker rm
Remove Image:
docker rmi
Containers are temporary (ephemeral). Data is lost when container is removed.
Method 1 – Commit Container:
docker commit
Method 2 – Create Volume: docker volume create myvolume
Run Container with Volume: docker run -v myvolume:/data image_name
Method 3 – Bind Mount: docker run -v /host/path:/container/path image_name
Dockerfile is used to build custom images.
Common Instructions:
FROM → Base image RUN → Execute commands COPY → Copy files ADD → Add files WORKDIR → Set working directory EXPOSE → Expose port ENV → Environment variable CMD → Default command ENTRYPOINT → Main container command
Build Image:
docker build -t image_name .

Docker Engine provides REST API for automation.
Check Docker API Version: curl –unix-socket /var/run/docker.sock http://localhost/version
Used For:
Modify daemon.json:
{ “hosts”: [“tcp://0.0.0.0:2375”, “unix:///var/run/docker.sock”] }
Restart Docker after modification.
⚠ Security Warning: Always secure Docker API with TLS authentication when exposing externally.
Check Logs:
docker logs
Inspect Container:
docker inspect
Monitor Resource Usage: docker stats
Execute Command Inside Container:
docker exec -it
Restart Container:
docker restart
Used to reduce image size and improve security.
Example Concept:
FROM node:18 AS builder WORKDIR /app COPY . . RUN npm install
FROM alpine
COPY –from=builder /app /app
CMD [“node”, “app.js”]

Benefits:
Best Practices:
Start Stopped Container:
docker start
Attach to Running Container:
docker attach
Run Interactive Shell:
docker exec -it
Volume (Docker Managed Storage): docker volume create myvolume
Run with Volume: docker run -v myvolume:/app image_name
Bind Mount (Host Directory Mapping): docker run -v /host/path:/container/path image_name
tmpfs (Temporary In-Memory Storage):
docker run –tmpfs /app image_name

List Networks:
docker network ls
Here it provde to ping the other container.
Create Network: docker network create mynetwork
Connect Container to Network: docker network connect mynetwork container_name
Default Network Types:
Theory —
These are essential concepts for containerized application deployment in modern DevOps environments.