Docker Interview Questions: 1).🔥 Docker Interview Questions (5+ Years Experience) 1. What is the difference between Docker Image and Container? Answer: * Image → Blueprint (read-only template) * Container → Running instance of image 👉 Example: docker build -t myapp . docker run -d myapp 2. Explain Docker Architecture Answer: * Docker Client * Docker Daemon (dockerd) * Docker Registry (Docker Hub / ECR) * Docker Objects (Images, Containers, Networks, Volumes) 👉 Check: docker info 3. What happens when you run docker run? Answer (Important): 1. Check image locally 2. Pull from registry if not present 3. Create container 4. Setup filesystem (UnionFS) 5. Allocate network 6. Start process 4. Difference: CMD vs ENTRYPOINT Answer: * CMD → Default command (can override) * ENTRYPOINT → Fixed command 👉 Example: CMD ["echo", "Hello"] ENTRYPOINT ["echo"] 5. Multi-stage build – Why? Answer: * Reduce image size * Remove build dependencies 👉 Example: FROM node:18 AS build WORKDIR /app COPY . . RUN npm install && npm run build FROM nginx:alpine COPY --from=build /app/build /usr/share/nginx/html 6. How do you reduce Docker image size? Answer: * Use Alpine base image * Multi-stage builds * Remove cache 👉 Example: RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* 7. Difference between COPY and ADD Answer: * COPY → Simple file copy * ADD → Supports URL + tar extraction 👉 Best Practice: Use COPY unless needed 8. What is Docker Volume? Answer: * Persistent storage outside container 👉 Example: docker volume create mydata docker run -v mydata:/data nginx 9. Bind Mount vs Volume Answer: * Bind Mount → Host path * Volume → Managed by Docker 10. Explain Docker Networking Types Answer: * bridge (default) * host * none * overlay (for Swarm/K8s) 👉 Check: docker network ls 11. How containers communicate? Answer: * Same network → via container name (DNS) 12. What is Docker Compose? Answer: * Multi-container management tool 👉 Example: version: '3' services: web: image: nginx db: image: mysql 👉 Run: docker-compose up -d 13. What is Dockerfile best practice? Answer: * Use minimal base images * Order layers properly * Avoid root user 14. What is .dockerignore? Answer: * Ignore unnecessary files 👉 Example: node_modules .git 15. How to debug a container? Answer: 👉 Logs: docker logs container_id 👉 Exec: docker exec -it container_id /bin/bash 16. Container is not starting – what will you do? (Scenario) Answer: 1. Check logs 2. Check port conflicts 3. Check CMD/ENTRYPOINT 4. Check resource limits 17. Difference: Detached vs Interactive mode docker run -d nginx docker run -it ubuntu 18. How do you expose ports? docker run -p 8080:80 nginx 19. What is Docker Registry? Answer: * Storage for images Examples: * Docker Hub * AWS ECR 20. How to push image? docker tag myapp username/myapp docker push username/myapp 21. What is container lifecycle? * Created * Running * Paused * Stopped * Removed 22. Resource limits in Docker? docker run -m 512m --cpus=1 nginx 23. What is Docker Swarm? Answer: * Native clustering tool 24. Difference between Docker and Kubernetes? Answer: * Docker → Container runtime * Kubernetes → Orchestration 25. Real-time Scenario 🔥 Problem: Container works locally but fails in server. Answer approach: * Check environment variables * Check ports * Check network/security group * Check image version mismatch 26. What is health check? HEALTHCHECK CMD curl --fail http://localhost || exit 1 27. How to handle secrets? Answer: * Use Docker secrets / env variables * Avoid hardcoding 28. How to clean unused resources? docker system prune -a 29. What is Layer caching? Answer: * Docker caches each step → faster builds 30. Explain real-time CI/CD Docker usage Answer: * Build image → push to registry → deploy via Kubernetes ==================== Kubernestes Interview questions: ========================== 🔥 DevOps Scenario-Based Interview (5+ Years) 1. 🚨 Deployment failed in production — what will you do? Answer approach (very important): * Check pipeline logs * Identify failure stage (Build / Deploy) * Rollback if critical 👉 Commands: kubectl rollout undo deployment my-app kubectl get pods kubectl logs pod-name 👉 Pro Answer Line: “First I ensure service availability by rollback, then I debug root cause.” 2. 🚨 Application is slow — how do you troubleshoot? Answer: * Check CPU/Memory * Check DB latency * Check network 👉 Commands: top kubectl top pod kubectl describe pod pod-name 👉 Tools: * Prometheus * Grafana * CloudWatch 3. 🚨 Pod is in CrashLoopBackOff Answer: * Check logs * Check env variables * Check config issues kubectl logs pod-name kubectl describe pod pod-name 4. 🚨 Website not accessible Answer: * Check Service * Check Ingress * Check DNS kubectl get svc kubectl get ingress kubectl get endpoints 5. 🚨 Docker container not starting Answer: * Check logs * Check CMD/ENTRYPOINT * Check port conflict docker logs container_id docker inspect container_id 6. 🚨 High CPU usage in server Answer: * Identify process * Kill or scale top ps -ef | grep java 7. 🚨 Disk space full Answer: df -h du -sh * 👉 Fix: * Clean logs * Remove unused Docker images docker system prune -a 8. 🚨 CI/CD pipeline is failing Answer: * Check pipeline logs * Validate credentials * Check syntax 👉 Example (Jenkins): * Check console output * Re-run stage 9. 🚨 Terraform apply failed Answer: terraform validate terraform plan terraform apply 👉 Debug: * State file issues * Resource conflict 10. 🚨 Infrastructure drift detected Answer: terraform plan 👉 Fix: * Re-apply or import resource 11. 🚨 LoadBalancer not working Answer: * Check security group * Check target health kubectl get svc kubectl describe svc 12. 🚨 Application logs not visible Answer: kubectl logs pod-name docker logs container_id 👉 Check: * Logging config * Sidecar (Fluentd) 13. 🚨 Secrets exposed in code Answer: * Move to: * Kubernetes Secrets * AWS Secrets Manager 14. 🚨 Multiple environments (Dev, QA, Prod) — how manage? Answer: * Use: * Separate namespaces * Separate pipelines * Terraform workspaces 15. 🚨 Zero downtime deployment — how? Answer: * Rolling updates * Blue-Green * Canary kubectl rollout status deployment my-app 16. 🚨 Pod cannot connect to DB Answer: * Check network * Check credentials * Check service name kubectl exec -it pod-name -- ping db-service 17. 🚨 API returning 500 error Answer: * Check logs * Check backend service * Check DB 18. 🚨 Kubernetes node NotReady Answer: kubectl get nodes kubectl describe node node-name 👉 Check: * kubelet * disk/memory 19. 🚨 SSL not working Answer: * Check certificate * Check Ingress 20. 🚨 Autoscaling not working Answer: kubectl get hpa kubectl describe hpa 👉 Check: * metrics-server 21. 🚨 Memory leak in app Answer: * Monitor usage * Restart pods * Fix code 22. 🚨 Network issue between services Answer: kubectl exec -it pod -- curl service-name 23. 🚨 Version rollback required kubectl rollout undo deployment 24. 🚨 Git conflict in pipeline Answer: * Resolve locally * Push again 25. 🚨 Monitoring alerts triggered Answer: * Check metrics * Identify spike * Take action 💥 Real Interview Question (Very Important) 👉 “Explain a production issue you handled” Perfect Answer Structure: 1. Problem 2. Impact 3. Action 4. Result 👉 Example: “We faced high latency in production. I checked metrics in Prometheus, identified high CPU usage, scaled pods using HPA, and resolved the issue with zero downtime.”

Comments

Popular posts from this blog

Linux interview Questions :

Linux interview questions